Builds an "upsert" using the SQLite/PostgreSQL ON CONFLICT ... DO UPDATE form. On conflict for conflictColumns, the listed update columns (or all non-conflict columns by default) are overwritten with the incoming values via the excluded pseudo-row.
ON CONFLICT ... DO UPDATE
conflictColumns
update
excluded
Target table name
Column to value map for the row to insert
Column(s) that trigger the conflict resolution
Upsert modifiers (update subset, RETURNING)
RETURNING
The parameterized SQL and its bindings
If no columns, no conflict columns, or an identifier is invalid
const { sql, bindings } = buildUpsert('kv', { k: 'a', v: '1' }, 'k');// sql: INSERT INTO "kv" ("k", "v") VALUES (?, ?) ON CONFLICT ("k") DO UPDATE SET "v" = excluded."v"// bindings: ['a', '1'] Copy
const { sql, bindings } = buildUpsert('kv', { k: 'a', v: '1' }, 'k');// sql: INSERT INTO "kv" ("k", "v") VALUES (?, ?) ON CONFLICT ("k") DO UPDATE SET "v" = excluded."v"// bindings: ['a', '1']
Builds an "upsert" using the SQLite/PostgreSQL
ON CONFLICT ... DO UPDATEform. On conflict forconflictColumns, the listedupdatecolumns (or all non-conflict columns by default) are overwritten with the incoming values via theexcludedpseudo-row.