admin管理员组文章数量:1289525
i am trying to update a set of data using Sequelize by this query
Users.update({
flag: 'flag & ~ 2'
} , {
where : {
id :{
gt : 2
}
}
})
the generated query is
UPDATE `users` SET `flag`='flag & ~ 2' WHERE id > 2
But is should be
UPDATE `users` SET `flag`=flag & ~ 2 WHERE id > 2
so my question is how can i update data by by it's old value
Regards
i am trying to update a set of data using Sequelize by this query
Users.update({
flag: 'flag & ~ 2'
} , {
where : {
id :{
gt : 2
}
}
})
the generated query is
UPDATE `users` SET `flag`='flag & ~ 2' WHERE id > 2
But is should be
UPDATE `users` SET `flag`=flag & ~ 2 WHERE id > 2
so my question is how can i update data by by it's old value
Regards
Share Improve this question asked Apr 9, 2015 at 9:43 hussamhussam 5945 silver badges12 bronze badges3 Answers
Reset to default 10You should be able to do this via:
Users.update({
flag: sequelize.literal('flag & ~ 2')
} , {
where : {
id :{
gt : 2
}
}
});
Simplest solution would be by using raw queries:
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.
})
You can do that with sequelize literal.
model.update({'count': sequelize.literal('count + 1')}, { where: { id: 1 }})
You can also do it with the increment method where by indicates from what value you want to increment.
Model.increment('seq', { by: 5, where: { id: 'model_id' });
本文标签: javascriptSequelize update by column it39s old valueStack Overflow
版权声明:本文标题:javascript - Sequelize: update by column it's old value - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741443343a2379046.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论