Skip to main content

UpdateQueryBuilder

Builder for constructing UPDATE queries with type-safe value updates.

Type Parameters

  • DB - The database schema type
  • UT - The table name being updated
  • TB - Union of table names available (for joins)
  • O - The output type (UpdateResult or custom with returning)

Methods

set

Sets the values to update. Takes an object whose keys are column names and values are values to update. The return value is an instance of UpdateResult. Use returning on supported databases to get the updated rows. Examples: Update a single row:
Complex values with callback:
Two-argument form:
With returning (PostgreSQL):
MySQL multi-table update:

where

Adds a WHERE clause to the query. Multiple where calls are combined with AND. See WhereInterface documentation for more examples.

whereRef

Adds a WHERE clause that compares two column references.

from

Adds a FROM clause to the update query (PostgreSQL). Example:

innerJoin

Joins another table using an inner join. See SelectQueryBuilder.innerJoin for examples.

leftJoin

Just like innerJoin but adds a left join instead.

rightJoin

Just like innerJoin but adds a right join instead.

fullJoin

Just like innerJoin but adds a full join instead.

returning

Adds a RETURNING clause to the query (supported on PostgreSQL, SQLite, MS SQL Server). Example:

returningAll

Adds a returning * or returning table.* clause to the query.

output

Adds an OUTPUT clause (MS SQL Server).

outputAll

Adds an output * clause (MS SQL Server).

top

Changes an update query to an update top query (MS SQL Server). Example:

limit

Adds a LIMIT clause to the update query (MySQL, SQLite with SQLITE_ENABLE_UPDATE_DELETE_LIMIT). Example:

orderBy

Adds an ORDER BY clause to the query (MySQL, SQLite with SQLITE_ENABLE_UPDATE_DELETE_LIMIT). See OrderByInterface documentation for more examples.

$call

Simply calls the provided function passing this as the only argument. Example:

$if

Call func(this) if condition is true. Especially handy with optional returning or returningAll calls. Example:

$castTo

Change the output type of the query.

$narrowType

Narrows (parts of) the output type of the query.

execute

Executes the query and returns an array of rows.

executeTakeFirst

Executes the query and returns the first result or undefined.

executeTakeFirstOrThrow

Executes the query and returns the first result or throws.

compile

Compiles the query to SQL without executing it.

stream

Streams the query results.

explain

Executes an EXPLAIN query.