我有以下代码,我试图在其中将记录插入SQLite数据库并尝试从中读取。
let stmt = db.prepare('INSERT INTO ratings(post_id, rating) VALUES (?, ?)')
stmt.run(1,4);
stmt.finalize()
// code above works succefully
let stmt2 = db.prepare(`SELECT AVG(rating) as avg_rating FROM ratings WHERE post_id = ?`)
stmt2.run(1, (err, row) => {
console.log(row) // here it returns undefined
});
stmt2.finalize()
但是正如我在注释代码中提到的那样,插入可以正常工作,但是在读取时,当我控制台登录它们时,row和err为null且未定义。我在哪里弄错了?
基本上如何在nodejs中从sqlite检索聚合函数的结果?