UpdateAllStatement<Tbl> class final Insert, Update & Delete

Batch UPDATE: one statement that updates many rows with per-row values, joining the target table against a VALUES table on the key column(s):

WITH "__basalt_values"("id", "stock") AS (VALUES (?, ?), (?, ?))
UPDATE "products" SET "stock" = "__basalt_values"."stock"
FROM "__basalt_values"
WHERE "products"."id" = "__basalt_values"."id"

Build with updateAll:

await db.execute(
  updateAll(Products.table).keyedBy(Products.id).values([
    for (final p in products)
      [Products.id.set(p.id), Products.stock.set(p.stock)],
  ]),
);

Every row must contain the key column(s); the remaining columns become the SET clause. Key values must be unique within one batch — when several VALUES rows match the same target row, SQL leaves which one wins undefined. Rows whose key matches nothing update nothing (the affected count only covers matched rows). Values are literals: TableColumn.set only — setExpr/setToExcluded don't fit a VALUES tuple.

Requires SQLite ≥ 3.33 (UPDATE ... FROM); any supported Postgres works.

Inheritance
Available extensions

Constructors

UpdateAllStatement(String table)

Properties

columns List<String>
Column names, recorded from the first row; every row must use the same columns in the same order.
final
columnTypes List<SqlType<Object?>?>
Each column's codec (parallel to columns) — lets a dialect cast the VALUES parameters when their type can't be inferred (Postgres).
final
hashCode int
The hash code for this object.
no setterinherited
keyColumns List<String>
Key column names set via keyedBy — the join between the target table and the VALUES table.
final
rows List<List<Object?>>
Encoded value tuples — one list per row.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
table String
final
whereNode ↔ SqlNode?
Extra predicate ANDed onto the key join (null = key join only).
getter/setter pair

Methods

keyedBy(TableColumn<Object?, Tbl> key) UpdateAllStatement<Tbl>
Declares key as a join key. Call once for a single-column key or repeatedly for a composite key. Every row passed to values must include the key column(s).
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
returning(List<TableColumn<Object?, Object?>> columns) Returning

Available on WriteStatement, provided by the WriteReturning extension

Return the given columns of the affected table after the write. Finish with .map(...) / .mapWith(...), then run via Connection.executeReturning:
toString() String
A string representation of this object.
inherited
values(Iterable<Iterable<ColumnValue<Tbl>>> valueRows) UpdateAllStatement<Tbl>
Adds rows: each element is one row's assignments (key included). Columns are taken from the first row; every row must use the same columns in the same order.
where(Expression<bool, Tbl> predicate) UpdateAllStatement<Tbl>
Extra filter on the target table, ANDed onto the key join — e.g. only touch rows that are still active.

Operators

operator ==(Object other) bool
The equality operator.
inherited