【发布时间】:2017-01-17 23:21:25
【问题描述】:
根据 nodejs sqlite 库 (https://github.com/mapbox/node-sqlite3),您可以使用 db.serialize 函数序列化 sql 事务。此函数中的所有执行都将按照指定的顺序执行。 但是使用 for 循环如何获取有关事务的信息是成功还是失败?
function transaction(callback) {
db.serialize(function() {
db.run("BEGIN");
for(...) {
db.run("INSERT", function(err) {
//this code is not serialized with the parent serialize function (this is my problem)
//if one run throw error i must resolve the callback with the error code
if (err)
callback("error");
});
}
db.run("END");
callback("ok");
}
}
【问题讨论】:
标签: node.js sqlite for-loop transactions