DeleteQueryBuilder is used to build and execute DELETE queries in Kysely. It provides a fluent API for deleting rows with type safety.
Basic Usage
Delete Rows
Delete rows from a table:Delete with Multiple Conditions
Returning Data
On PostgreSQL and SQLite, you can usereturning to get deleted rows:
Using Clause (PostgreSQL, MySQL)
PostgreSQL: Using for Additional Tables
Theusing clause allows adding additional tables for filtering:
MySQL: Using with Joins
On MySQL, theusing clause allows using joins:
Multiple Tables in Using
Delete with Joins
You can join tables to delete based on related data:Limit and Order By
Limit (MySQL)
Limit the number of deleted rows on MySQL:Order By (MySQL)
Top Clause (MS SQL Server)
Delete the first N rows:Where Conditions
All the standard where methods are available:Clear Methods
Clear parts of the query:API Reference
Main Methods
deleteFrom(table)- Specify the table to delete fromwhere(...)- Add WHERE conditionswhereRef(...)- Add WHERE conditions comparing columnsusing(table)- Add USING clause for additional tablesinnerJoin(),leftJoin(),rightJoin(),fullJoin()- Join tablesorderBy(...)- Order rows before deletion (MySQL)limit(n)- Limit number of deleted rows (MySQL)top(n)- Delete top N rows (MS SQL Server)returning(...)- Return columns from deleted rowsreturningAll()- Return all columns from deleted rowsclearWhere()- Clear WHERE conditionsclearOrderBy()- Clear ORDER BY clausemodifyEnd(modifier)- Add custom SQLexecute()- Execute the queryexecuteTakeFirst()- Execute and return first resultexecuteTakeFirstOrThrow()- Execute and return first result or throw
Result Object
The return value is an instance ofDeleteResult: