Skip to content
Permalink
8d5211f807
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
37 lines (32 sloc) 893 Bytes
'use strict'
const Database = require('sqlite-async')
const dbName = 'server.db'
module.exports = class Question {
async getAllQuestions(query) {
try {
let sql = 'SELECT id, title, question FROM Questions;'
console.log(query.search)
if(query !== undefined && query.search !== undefined) {
sql = `SELECT id, title, question FROM Questions
WHERE upper(title) LIKE "%${query.search}%";`
}
const db = await Database.open(dbName)
const data = await db.all(sql)
await db.close()
console.log(data)
return data
} catch(err) {
return err.message
}
}
async insertQuestion(request) {
console.log(request.body)
const body = request.body
const sql = `INSERT INTO Questions(title, question)
VALUES("${body.title}", "${body.question}");`
console.log(sql)
const db = await Database.open(dbName)
await db.run(sql)
await db.close()
}
}