Sequelize: update column old value

I am trying to update a dataset using Sequelize for this query

Users.update({ flag: 'flag & ~ 2' } , { where : { id :{ gt : 2 } } }) 

generated request

 UPDATE `users` SET `flag`='flag & ~ 2' WHERE id > 2 

But there must be

 UPDATE `users` SET `flag`=flag & ~ 2 WHERE id > 2 

so my question is how can I update the data with the old value

Hi

+5
source share
2 answers

You should be able to do this through:

 Users.update({ flag: sequelize.literal('flag & ~ 2') } , { where : { id :{ gt : 2 } } }); 
+7
source

The simplest solution would be to use raw requests :

 sequelize.query("UPDATE users SET flag=flag & ~ 2 WHERE id > 2").spread(function(results, metadata) { // Results will be an empty array and metadata will contain the number of affected rows. }) 
0
source

All Articles