Reputation: 775
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?
Upvotes: 8
Views: 12606
Reputation: 775
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.
Upvotes: 15