Here it is :
db.table.update({ field: Sequelize.literal('data + 1') }, { where: { id: 1 }}))
OR
User.findById(1).then(user => {
// -----> First Way
return user.increment('my-integer-field', {by: 2});
// -----> Second Way
return user.increment([ 'my-integer-field', 'my-very-other-field' ], {by: 2})
// -----> Third Way
return user.increment({
'my-integer-field': 2,
'my-very-other-field': 3
})
});
You can also do decrement
by just replacing increment
with decrement
.
For more detail : DO READ
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…