Skip to content
Permalink
48e450480a
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
66 lines (59 sloc) 1.9 KB
const sqlite = require('sqlite-async')
const config = require('../config.json')
module.exports = class GitContent {
//CONSTRUCTOR FOR THE DB
constructor(dbName = ':memory:'){
return (async() => {
this.db = await sqlite.open(dbName)
const sql = 'CREATE TABLE IF NOT EXISTS git_content (\
id INTEGER PRIMARY KEY AUTOINCREMENT,\
title_of_content TEXT, block_of_content TEXT\
);'
//STILL need TO INSERT IMAGE HERE
await this.db.run(sql)
return this
})()
}
//INSERT content IN DATABASE
async content(title_of_content, block_of_content) //STILL NEED TO INSERT IMAGE HERE
{
try{
console.log('ADD content')
const sql = `INSERT INTO git_content(title_of_content, block_of_content)\
VALUES("${title_of_content.title_of_content}","${title_of_content.block_of_content}")`
console.log(sql)
await this.db.run(sql)
} catch(err){
console.log(err.message)
throw err
}
}
//SELECT ALL GIT CONTENT
async all() {
try{
console.log('ALL answers')
const sql = 'SELECT id, title_of_content, block_of_content FROM git_content'
console.log(sql)
const gitselected = await this.db.all(sql)
console.log(gitselected)
return gitselected
} catch(err){
console.log(err.message)
throw err
}
}
//GETS THE ID
async getById(id){
try{
console.log('BY ID')
console.log(id)
const sql =`SELECT * FROM git_content WHERE id=${id}`
console.log(sql)
const contentdb = await this.db.get(sql)
return contentdb
} catch(err) {
console.log(err.message)
throw err
}
}
}