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

DOCSAPITable API


Programmatically perform an 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 building.

DeleteOptions

interface DeleteOptions {
    where?: WhereClause;
    returning?: Field[];
}
Param Interfaces Description
where? WhereClause Optional WHERE clause.
returning? Field Optional list of fields to return from the just created 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

Basic 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: 'johndoe@example.com' }]
    }, returning: ['*'] }
);

Return the just deleted record (object):

// A "find-one" condition
const deletedRecord = await table.delete(
    { where: 4, returning: ['*'] }
);

Returning Records

Return the just created record (object):

// ...limited to just the "id" column
const insertedRows = await table.insert(
    { first_name: 'John', last_name: 'Doe', email: 'johndoe@example.com'},
    { returning: ['id'] }
);

Return the just created records (array):

// ...limited to just the "id" column per record
const insertedRows = await table.insert(
    [
        { first_name: 'John', last_name: 'Doe', email: 'johndoe@example.com'}
    ],
    { returning: ['id'] }
);

Find-by-ID

Clone this wiki locally