import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { OnConflictBuilder } = kysely;
Adds the "do update set" conflict action.
Examples
await db
.insertInto('person')
.values({ first_name, pic })
.onConflict((oc) => oc
.column('pic')
.doUpdateSet({ first_name })
)
The generated SQL (PostgreSQL):
insert into "person" ("first_name", "pic")
values ($1, $2)
on conflict ("pic")
do update set "first_name" = $3
In the next example we use the ref
method to reference
columns of the virtual table excluded
in a type-safe way
to create an upsert operation:
db.insertInto('person')
.values(person)
.onConflict((oc) => oc
.column('id')
.doUpdateSet((eb) => ({
first_name: eb.ref('excluded.first_name'),
last_name: eb.ref('excluded.last_name')
}))
)
Parameters
update: UpdateObjectExpression<OnConflictDatabase<DB, TB>, OnConflictTables<TB>, OnConflictTables<TB>>
Returns
OnConflictUpdateBuilder<OnConflictDatabase<DB, TB>, OnConflictTables<TB>>