【发布时间】:2013-08-14 15:53:48
【问题描述】:
我正在使用 node-mysql-queues 在我的应用程序中处理数据库事务。
for (lineitem in lineitems) {
transaction.query("SELECT n from inventory WHERE productId = ?", [lineitem], function (err, rows) {
if (err)
transaction.rollback();
var newN = rows[0].n - lineitems[lineitem].quantity;
if (newN >= 0) {
transaction.query("UPDATE inventory SET n = ? WHERE productId = ?", [newN, lineitem], function (err) {
if (err){
transaction.rollback();
console.log(err);
}
//here I want to commit if all updates were successfull!!!
});
}
})
}
正如您在代码中看到的,我不知道如何处理提交部分。如果是同步的就好了,但是不知道怎么解决这个问题。
感谢和问候
【问题讨论】:
标签: node.js asynchronous transactions node-mysql