Delete
Builds a DELETE FROM ... query. Extends Query directly — it has no RETURNING
support. See the Delete Statement guide for a
full walkthrough.
Constructor
Delete(tableName: string | TableName | Raw): Delete
new Delete(tableName: string | TableName | Raw): Delete
Dual-callable. tableName must be a non-empty string, a TableName, or a
Raw instance, otherwise throws a TypeError:
"String or Raw instance required as first argument (tableName) for Delete".
import { Delete, Eq } from '@sqb/builder';
Delete('customers').where(Eq('id', 1));
Properties
| Key | Type | Readonly | Description |
|---|---|---|---|
_type | SerializationType.DELETE_QUERY | Yes | Discriminates this node during serialization. |
_table | TableName | Raw | No | The target table, set from the constructor's tableName argument. |
_where | LogicalOperator | undefined | No | The implicit top-level And built by .where(). |
Plus everything inherited from Query (_comment, _params, EventEmitter).
Methods
where()
where(...condition: any[]): this
Accumulates conditions into an implicit top-level And, identical to
Select#where(). See
Operators and Conditions. Omitting
.where() deletes every row in the table.
Delete('customers').where(Eq('id', 1)).generate().sql;
// delete from customers where id = 1
generate(), values(), comment()
Inherited from Query.