Basics

Override: Insert & Upsert

Override helpers add explicit insertInto, flexiblevalues, and PostgreSQL upsert helpers.

Insert Into

Use insertInto to define the table and columns explicitly.



const query = q
  .insertInto(q.t("users"), [q.c("email"), q.c("status")])
  .values([q.v("hello@example.com"), q.v("active")])

Insert Values

The insert helper builds columns and rows from objects.

const query = q.insert(q.t("users"), {
  email: q.v("hello@example.com"),
  status: q.v("active"),
})

On Conflict

onConflictDoUpdate and onConflictDoNothingwrap PostgreSQL upserts.

const query = q
  .insert(q.t("users"), {
    email: q.v("hello@example.com"),
    status: q.v("active"),
  })
  .onConflictDoUpdate({
    target: [q.c("users.email")],
    set: { status: q.v("active") },
  })
  .returning(q.c("users.id"))

Conflict Targets

Use onConflict or onConstraint to define the target index/constraint.

const query = q
  .insert(q.t("users"), {
    email: q.v("hello@example.com"),
    status: q.v("pending"),
  })
  .onConflict(
    [q.c("users.email")],
    q.eq(q.c("users.status"), q.v("pending")),
  )
  .doUpdate({ status: q.v("active") })

Conflict Actions

Use doUpdate and doNothing for explicit conflict handling.

const query = q
  .insert(q.t("users"), {
    email: q.v("hello@example.com"),
    status: q.v("active"),
  })
  .onConstraint(q.i("users_email_key"))
  .doNothing()