Skip to main content

Delete Statement

Delete(tableName) builds a DELETE FROM ... statement.

import { Delete, Eq } from '@sqb/builder';

const query = Delete('customers').where(Eq('id', 1));
query.generate().sql;
// delete from customers where id = 1

Delete is dual-callable and extends Query directly (it has no RETURNING support) — see the Delete class reference for the full member list.

Arguments

Delete(tableName: string | TableName | Raw): Delete

tableName accepts a table name string, a TableName instance, or a Raw fragment. Anything else (including null/undefined) throws a TypeError:

Delete(null);
// TypeError: String or Raw instance required as first argument (tableName) for Delete

where()

.where(...) accumulates conditions into an implicit top-level And, exactly like Select and Update. See Operators and Conditions. Omitting .where() deletes every row in the table:

Delete('customers');
// delete from customers

Delete('customers').where(Eq('id', 1));
// delete from customers where id = 1

Raw as table name

A plain string only parses [schema.]table [as alias] — one optional schema level. For anything that shape can't express, such as a 3-level qualified name, fall back to Raw:

Delete('mydb.public.customers');
// TypeError: (mydb.public.customers) does not match table name format

Delete(Raw('mydb.public.customers')).generate().sql;
// delete from mydb.public.customers

Delete has no .returning() support (unlike Insert/Update) and no RETURNING-related serialization type. If your target dialect supports DELETE ... RETURNING, express it with Raw or a dialect-level extension — see Generating SQL per dialect.