问题描述
我试图弄清楚如何将sqlite与Node JS一起使用。当我问数据库想要什么时,我不知道如何使用行。我在网上无处不在,但没人能真正解释获取完成后如何使用该行。
我的意思是它返回该行,但我不能使用它。
const sqlite3 = require('sqlite3').verbose();
// open the database
let db = new sqlite3.Database('./db/chinook.db');
let sql = `SELECT PlaylistId id,Name name
FROM playlists
WHERE PlaylistId = ?`;
let playlistId = 1;
// first row only
var test = db.get(sql,[playlistId],(err,row) => {
if (err) {
return console.error(err.message);
}
return row
? console.log(row.id,row.name)
: console.log(`No playlist found with the id ${playlistId}`);
});
//What I added to try to use the row after the get is done
console.log(test.id) // I get "undefined" here. How are we really suppose to do it?
// close the database connection
db.close();
此代码来自here
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)