import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { QueryCreator } = kysely;
Creates a merge query.
The return value of the query is a MergeResult.
See the {@link MergeQueryBuilder.using} method for examples on how to specify the other table.
Examples
const result = await db
.mergeInto('person')
.using('pet', 'pet.owner_id', 'person.id')
.whenMatched((and) => and('has_pets', '!=', 'Y'))
.thenUpdateSet({ has_pets: 'Y' })
.whenNotMatched()
.thenDoNothing()
.executeTakeFirstOrThrow()
console.log(result.numChangedRows)
The generated SQL (PostgreSQL):
merge into "person"
using "pet" on "pet"."owner_id" = "person"."id"
when matched and "has_pets" != $1 then
update set "has_pets" = $2
when not matched then
do nothing
Parameters
targetTable: TR
Parameters
targetTable: TR
Returns
MergeQueryBuilder<DB & PickTableWithAlias<DB, TR>, ExtractTableAlias<DB & PickTableWithAlias<DB, TR>, TR>, MergeResult>