I am using sequalize transaction in Nodejs,but my problem is that it don't take my users
table in Transaction and update my table
return sequelize.transaction(function (t) {
var Users = objAllTables.users.users();
return Users.update(updateUser, {
where: {
uid: sessionUser.uid,
status: 'ACTIVE'
}
},{ transaction: t }).then(function (result) {
return Utils.sendVerificationEmail(sessionUser.uid, sessionUser.user_email)
.then(function(data){
data = false;
if(data == false){
throw new Error('Failed Email');
}
});
}).then(function (result) {
console.log(result);
// Transaction has been committed
// result is whatever the result of the promise chain returned to the transaction callback
})
}).catch(function(err){
res.send({message:err.message})
})
CONSOLE:
Executing (ad5247bd-18b8-4c6f-bb30-92744c7a5ac8): START TRANSACTION;
Executing (ad5247bd-18b8-4c6f-bb30-92744c7a5ac8): SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ;
Executing (ad5247bd-18b8-4c6f-bb30-92744c7a5ac8): SET autocommit = 1;
Executing (default): UPDATE `users` SET `username`='edited' WHERE `uid` = 20 AND `status` = 'ACTIVE'
Executing (ad5247bd-18b8-4c6f-bb30-92744c7a5ac8): ROLLBACK;
As you can see in the console update query run out of the transaction
First, you get an instance of the Model by calling the create() or findOne() method. Once you have the instance, you call the set() method to change the values of the instance. Then, you need to call the save() method on the instance to persist the changes to your table row.
transaction
key must be in options
:
return Users.update(updateUser, {
where: {
uid: sessionUser.uid,
status: 'ACTIVE'
},
transaction: t //second parameter is "options", so transaction must be in it
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With