我对 node.js 有点陌生,我知道如何将它与 SQLite 一起使用,但我想制作包装函数,这样我就不必在我的代码中包含 SQL 语句。此代码打印出查询结果:
Users.find_by_id = function(id){
db.all("SELECT * from users WHERE id=" + id, function(err, row){
console.log(row);
});
};
我知道node.js是异步的,所以我无法返回值本身,但我想知道是否可以返回带有相关值的 promise 。
最佳答案
如果你想使用 Promise,有很多包可以使用。我喜欢 Q。如果没有 promise ,您可以将回调函数作为参数,并在完成后调用它,将数据传递给函数。
关于javascript - Node.js SQLite 3 返回 promise ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35584798/