简体   繁体   中英

sequelize update transaction

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

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
    })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM