DELETE Examples

Simple DELETE

Delete an entity using the db.delete driver method:

db.delete(new Contact({ id:1, name:'John', email:'[email protected]', age:27 }))

DELETE Query Builder

When a custom query is needed you can use $.deleteFrom() to create a DELETE query builder:

const yearAgo = new Date(new Date().setFullYear(new Date().getFullYear() - 1)) db.run($.deleteFrom(Order).where(c => $`${c.createdAt} < ${yearAgo}`))

DELETE Expression

When the full flexibility of SQL is needed, you can execute a SQL fragment directly:

const name = 'John' db.run`DELETE FROM Contact WHERE name = ${name}`