Update
Builds an UPDATE ... SET ... query. Extends ReturningQuery (which
extends Query). See the
Update Statement guide for a full
walkthrough.
Constructor
Update(tableName: string | TableName | Raw, input: Record<string, any> | Select | Raw): Update
new Update(tableName: string | TableName | Raw, input: Record<string, any> | Select | Raw): Update
Dual-callable. Validates both arguments and throws a TypeError if they don't match:
tableNamemust be a string, aTableName, or aRawinstance, otherwise:"String or Raw instance required as first argument (tableName) for Update".inputmust be a plain object, aSelect, or aRawinstance (not an array), otherwise:"Object or Raw instance required as second argument (input) for Update".
import { Update, Eq } from '@sqb/builder';
Update('customers', { name: 'Jane' }).where(Eq('id', 1));
Properties
| Key | Type | Readonly | Description |
|---|---|---|---|
_type | SerializationType.UPDATE_QUERY | Yes | Discriminates this node during serialization. |
_table | TableName | Raw | No | The target table, set from the constructor's tableName argument. |
_input | Record<string, any> | Select | Raw | No | The column values / sub-select set from the constructor's input argument. |
_where | LogicalOperator | undefined | No | The implicit top-level And built by .where(). |
Plus everything inherited from ReturningQuery (_returningColumns,
_comment, _params, EventEmitter).
Methods
where()
where(...condition: any[]): this
Accumulates conditions into an implicit top-level And, exactly like
Select#where(). See
Operators and Conditions. Omitting
.where() updates every row in the table.
Update('customers', { id: 2, name: 'aaa' }).where(Eq('id', 1)).generate().sql;
// update customers set id = 2, name = 'aaa' where id = 1
returning(), generate(), values(), comment()
Inherited from ReturningQuery and Query.