Adds the ability to use raw SQL in update.
Currently, you cannot add raw SQL to the SET portion of update statements, which prevents generating SQL like SET field1 = field1 + 1
, as discussed in Issue 734.
This MR is a suggestion for allowing that, via code like this:
const tests = await db.tests.update(1, {
$set: {field1: '"field1" + 1'},
});
The above generates the following SQL:
UPDATE "tests SET "field1" = "field1" + 1 WHERE id = 1 RETURNING *
Additionally, attempting to set the same field in the changes map and the $set map will throw an error:
const tests = await db.tests.update(1, {
$set: {field1: '"field1" + 1'},
field1: 'value',
});
Returns:
'The key 'field1' may not be defined in both the change map and the $set map.'
Edited by Dan Hulton