Skip to content
Oxford Harrison edited this page Nov 12, 2024 · 10 revisions

DOCSAPITable API


Programmatically perform a DELETE query.

See also ➞ DELETE

Syntax

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.

DeleteOptions

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.

DeleteResult

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.

Usage

Call pattern

Delete all records:

// { where: true } being a good practice
await table.delete(
    { where: true }
);

Find one

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 }
);

Returning records

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: ['*'] }
);
Clone this wiki locally