I'm using knex with node.js I want to do a math query (I want to add +1 to already existing values)
I want to do this in knex
UPDATE fares SET fare=fare + 70
This is my query in knex, all I get is 0 in the database
knex('table').update({ fares: 'fares' + 70}).then(function() {});
You don't need to use .raw(), although it will work fine. There is built-in capability to increment using .increment(). See: doc link
Sample from the docs:
knex('accounts')
.where('userid', '=', 1)
.increment('balance', 10)
... and, using your table/field names, and a value variable for the update amount.
knex('fares')
.increment('fare', fareIncrementAmount)
Happy coding!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With