Skip to main content

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

KeyTypeReadonlyDescription
_typeSerializationType.DELETE_QUERYYesDiscriminates this node during serialization.
_tableTableName | RawNoThe target table, set from the constructor's tableName argument.
_whereLogicalOperator | undefinedNoThe 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.

See also