I am trying the transaction for sequelize in noodejs. I am using postgres as my database. When I call the testDel the transaction get autocommitted in the testDel. Even if transaction autocommit already set to false.
If I pass the variable t from the Db.transaction to testDel, then it will wait for the manual commit / rollback. Can I do without passing t into function? It make coding very complicated.
The coding is as following:
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;
})
}
See Question&Answers more detail:os