【发布时间】:2017-04-25 23:51:08
【问题描述】:
我是 nodejs 新手,遇到了 sqlite 选择查询问题
下面是我的代码。
function parse(topic, msg, name) {
item = get_obj(tbl_name, handle, JSON.stringify(arg))
// get item from database
return [handle, arg, item, action];
}
function get_obj(tbl_name, handle, obj_str) {
let dbname = "test.sql";
let query, ret;
let my_obj = {};
let db = new sql.Database(dbname);
let str = "'" + obj_str + "'";
query = "SELECT handle from " + tbl_name + " where object=" + str;
db.serialize(function(ret) {
let ret1 = db.each(query, function(err, row, ret) {
if (err) {
console.log("No records found");
} else {
if (row.handle == handle) {
ret = JSON.parse(obj_str);
}
}
});
});
}
我希望我的解析应该等到我完成 get_obj()。在当前情况下,我的解析立即返回。任何帮助表示赞赏。
【问题讨论】:
标签: node.js select asynchronous sqlite