Skip to main content

DELETE

For WHERE examples, please see the WHERE section.

Delete all rows

QueryBuilder

import { QueryBuilder } from 'mysql2-orm';

const { sql, params } = QueryBuilder.delete({
table: 'temp',
});

MySQL2 ORM Class

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

await pool.delete({
table: 'temp',
});

SQL Query

DELETE FROM `temp`

Limit the rows to be deleted

QueryBuilder

import { QueryBuilder } from 'mysql2-orm';

const { sql, params } = QueryBuilder.delete({
table: 'test',
limit: 1,
});

MySQL2 ORM Class

import { MySQL } from 'mysql2-orm';

const pool = new MySQL({
// ...
});

await pool.delete({
table: 'test',
limit: 1,
});

SQL Query

DELETE FROM `test` LIMIT ?
-- params: ['1']