Class MatchedThenableMergeQueryBuilder<DB, TT, ST, UT, O>

Type Parameters

  • DB
  • TT extends keyof DB
  • ST extends keyof DB
  • UT extends TT | ST
  • O

Constructors

Properties

#private: any

Methods

  • Performs the delete action.

    To perform the do nothing action, see thenDoNothing.

    To perform the update action, see thenUpdate or thenUpdateSet.

    Examples

    const result = await db.mergeInto('person')
    .using('pet', 'person.id', 'pet.owner_id')
    .whenMatched()
    .thenDelete()
    .execute()

    The generated SQL (PostgreSQL):

    merge into "person"
    using "pet" on "person"."id" = "pet"."owner_id"
    when matched then
    delete

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>

  • Performs the do nothing action.

    This is supported in PostgreSQL.

    To perform the delete action, see thenDelete.

    To perform the update action, see thenUpdate or thenUpdateSet.

    Examples

    const result = await db.mergeInto('person')
    .using('pet', 'person.id', 'pet.owner_id')
    .whenMatched()
    .thenDoNothing()
    .execute()

    The generated SQL (PostgreSQL):

    merge into "person"
    using "pet" on "person"."id" = "pet"."owner_id"
    when matched then
    do nothing

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>

  • Perform an update operation with a full-fledged UpdateQueryBuilder. This is handy when multiple set invocations are needed.

    For a shorthand version of this method, see thenUpdateSet.

    To perform the delete action, see thenDelete.

    To perform the do nothing action, see thenDoNothing.

    Examples

    import { sql } from 'kysely'

    const result = await db.mergeInto('person')
    .using('pet', 'person.id', 'pet.owner_id')
    .whenMatched()
    .thenUpdate((ub) => ub
    .set(sql`metadata['has_pets']`, 'Y')
    .set({
    updated_at: Date.now(),
    })
    )
    .execute()

    The generated SQL (PostgreSQL):

    merge into "person"
    using "pet" on "person"."id" = "pet"."owner_id"
    when matched then
    update set metadata['has_pets'] = $1, "updated_at" = $2

    Type Parameters

    Parameters

    • set: ((ub) => QB)
        • (ub): QB
        • Parameters

          Returns QB

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>

  • Performs an update set action, similar to UpdateQueryBuilder.set.

    For a full-fledged update query builder, see thenUpdate.

    To perform the delete action, see thenDelete.

    To perform the do nothing action, see thenDoNothing.

    Examples

    const result = await db.mergeInto('person')
    .using('pet', 'person.id', 'pet.owner_id')
    .whenMatched()
    .thenUpdateSet({
    middle_name: 'dog owner',
    })
    .execute()

    The generate SQL (PostgreSQL):

    merge into "person"
    using "pet" on "person"."id" = "pet"."owner_id"
    when matched then
    update set "middle_name" = $1

    Type Parameters

    Parameters

    • update: UO

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>

  • Type Parameters

    • U extends UpdateObjectFactory<DB, UT, TT>

    Parameters

    • update: U

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>

  • Type Parameters

    • RE extends string | Expression<any> | DynamicReferenceBuilder<any> | SelectQueryBuilderExpression<Record<string, any>> | OperandExpressionFactory<DB, TT, any>
    • VE extends any

    Parameters

    Returns WheneableMergeQueryBuilder<DB, TT, ST, O>