Skip to content
Permalink
a8fdbf4ca9
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
31 lines (25 sloc) 646 Bytes
'use strict'
const Database = require('sqlite-async')
const dbName = 'server.db'
module.exports = class Question {
example() {
return 'this is an example'
}
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
}
}
}