Title basically says it all.
I am predominantly interested in the update case. Suppose we are trying update a record that has a timestamp field, and we wish to set that field to the timestamp of when the record is updated. Is there a way to do this?
After some experimentation, I've figured out the proper solution. You can use multiple .update(...)
calls on the same query without screwing anything up, so long as you don't use multiple objects (this includes knex.raw
). You can combine one object style call with field/value style calls, such as:
knex('table').update({ x: 1, y: 2 }).update('modified_at', knex.fn.now()).where(...) // and so on.
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