-
-
Notifications
You must be signed in to change notification settings - Fork 2
table.delete()
Oxford Harrison edited this page Nov 12, 2024
·
10 revisions
Programmatically perform a DELETE
query.
See also ➞
DELETE
table.delete(
modifiers?: DeleteOptions | Callback,
): Promise<DeleteResult>;
Param | Interfaces | Description |
---|---|---|
modifiers? |
DeleteOptions |
Optional additional query modifiers. Can be Callback —a callback function that recieves the underlying DeleteStatement instance for manipulation. |
interface DeleteOptions {
where?: WhereClause;
returning?: Field[];
}
Param | Interfaces | Description |
---|---|---|
where? |
WhereClause |
An optional WHERE clause. |
returning? |
Field |
Optional list of fields to return from the deleted records. |
type DeleteResult = number | Array<object> | object;
Type | Interfaces | Description |
---|---|---|
number |
- | The default delete result—a number indicating the number of records deleted. |
Array<object> |
- | The default delete result when a RETURNING clause is specified—an array of objects representing the deleted records. |
object |
- | The delete result when a RETURNING clause is specified in combination with a find-one condition—an object representing the deleted record. |
Delete all records:
// { where: true } being a good practice
await table.delete(
{ where: true }
);
Find by ID—with actual ID name automatically figured by Linked QL:
/**
* DELETE ...
* WHERE automatically_figured_primary_key_name = 4
*/
await table.select(
{ where: 4 }
);
Return the just deleted records (array):
// Delete all records that match and return all
const deletedRecords = await table.delete(
{ where: {
eq: ['email', { value: '[email protected]' }]
}, returning: ['*'] }
);
Return the just deleted record (object):
// A "find-one" condition
const deletedRecord = await table.delete(
{ where: 4, returning: ['*'] }
);