Sequelize update - balance

Viewed 25

I can't figure out how I can subtract 50 from the amount of 100 Using sequelize mysql. What.How do I do it?

var us = await User.findOne({ where: { userID: ctx.from.id } })
await us.update({balance: -50?})
1 Answers

You can reference the current balance in your code while updating:

var us = await User.findOne({ where: { userID: ctx.from.id } })
await us.update({balance: us.balance - 50})
Related