我正在Node.js和Express中实现一个小型的Web服务器,我想知道如何在数据库回调中访问数据变量? 整个代码在快速路由函数内,db是sqlite3
var data = {
color: "blue",
}
db.all("SELECT * FROM connections WHERE ip='" + req.connection.remoteAddress + "' AND connection='connected'",function(err,rows){
console.log(rows.length)
if (rows.length > 0) {
data["color"] = "green";
}else {
data["color"] = "red";
}
});