Delete
delete() removes matching rows. Add where() to scope it.
Delete with a filter
Section titled “Delete with a filter”await db.from(users).where("id", "=", 1).delete();Delete all rows
Section titled “Delete all rows”Omit where() to delete everything in the table:
await db.from(users).delete();How it compiles
Section titled “How it compiles”db.from(users).where("id", "=", 1).delete();// → DELETE FROM "users" WHERE "id" = ?Real-world example
Section titled “Real-world example”export async function removeUser(id: number) { await db.from(users).where("id", "=", id).delete();}Best practices
Section titled “Best practices”- Always scope deletes with
where()unless you intend a full clear. - Consider a soft-delete (
update({ deletedAt })) for recoverable data. - Wrap destructive deletes in a transaction when multiple tables are involved.
Common mistakes
Section titled “Common mistakes”- Forgetting
where()and wiping the table. - Deleting without a FK
ON DELETEstrategy — orphans may remain.
