【发布时间】:2020-07-12 01:21:49
【问题描述】:
我正在使用 tutorial 进行 JWT/bcryptjs 身份验证,然后将 INSERT 用于 SQlite
桌子。
事情是这个教程是针对 MySQL 的,我得到了像 db.query is not a function 这样的错误
和db.escape is not a function
数据库:
const sqlite3 = require('sqlite3').verbose()
const DBSOURCE = "./src/db/db.sqlite"
let db = new sqlite3.Database(DBSOURCE, (err) => {
if (err) {
// Cannot open database
console.error(err.message)
throw err
}else{
console.log('Connected to the SQLite database.')
}
});
module.exports = db
查询示例:
db.query(
`SELECT * FROM users WHERE LOWER(username) = LOWER(${db.escape(
req.body.username
)});`,
(err, result) => {
if (result.length) {
return res.status(409).send({
msg: 'This username is already in use!'
});
} else { .........
我最好的猜测是功能不同?
我怎样才能做到这一点?
【问题讨论】: