Module

x/kysely_postgrs_js_dialect/mod.ts>kysely.MatchedThenableMergeQueryBuilder#thenUpdate

Kysely dialect for PostgreSQL using the Postgres.js client.
Latest
method kysely.MatchedThenableMergeQueryBuilder.prototype.thenUpdate
import { kysely } from "https://dotland.deno.dev/x/kysely_postgrs_js_dialect@v0.27.4/mod.ts";
const { MatchedThenableMergeQueryBuilder } = kysely;

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 {@link thenUpdateSet}.

To perform the delete action, see {@link thenDelete}.

To perform the do nothing action, see {@link 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

QB extends UpdateQueryBuilder<DB, TT, UT, never>

Parameters

set: (ub: QB) => QB