import { kysely } from "https://deno.land/x/kysely_postgrs_js_dialect@v0.27.4/deps.ts";
const { WheneableMergeQueryBuilder } = kysely;
Adds the when not matched
clause to the query with an and
condition.
This method is similar to SelectQueryBuilder.where, so see the documentation for that method for more examples.
For a simple when not matched
clause (without an and
condition) see whenNotMatched.
Unlike whenMatchedAnd, you cannot reference columns from the table merged into.
Examples
const result = await db.mergeInto('person')
.using('pet', 'person.id', 'pet.owner_id')
.whenNotMatchedAnd('pet.name', '=', 'Lucky')
.thenInsertValues({
first_name: 'John',
last_name: 'Doe',
})
.execute()
The generated SQL (PostgreSQL):
merge into "person"
using "pet" on "person"."id" = "pet"."owner_id"
when not matched and "pet"."name" = $1 then
insert ("first_name", "last_name") values ($2, $3)
Type Parameters
RE extends ReferenceExpression<DB, ST>
VE extends OperandValueExpressionOrList<DB, ST, RE>
Returns
NotMatchedThenableMergeQueryBuilder<DB, TT, ST, O>
Type Parameters
E extends ExpressionOrFactory<DB, ST, SqlBool>
Parameters
expression: E
Returns
NotMatchedThenableMergeQueryBuilder<DB, TT, ST, O>