【发布时间】:2016-04-21 18:00:11
【问题描述】:
我正在尝试在 noodejs 中进行续集交易。我使用 postgres 作为我的数据库。当我调用 testDel 时,事务会在 testDel 中自动提交。即使事务自动提交已经设置为 false。
如果我将变量 t 从 Db.transaction 传递给 testDel,那么它将等待手动提交/回滚。 我可以不将 t 传递给函数吗?它使编码变得非常复杂。
编码如下:
Db.transaction({autocommit: false}).then((t) => {
args = {vcTitle: {$ilike: '%ulie%'}};
let boDelete = true;
testDelPost(t, args)
.then(rersult =>{
if(rersult){
t.commit();
}else{
t.rollback();
}
})
});
function testDel(args){
//the result got deleted and auto committed after this destroy, it
//doesn't wait for the above transaction to decide the commit or rollback.
//If I pass t, and set traction: t in the destroy, then it work as expected
return Db.models.Post.destroy({where: args})
.then(result =>{
if(result > 0){
return true;
}else{
return false;
}
})
.error(status =>{
return error;
})
}
【问题讨论】:
标签: postgresql transactions sequelize.js