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

DOCSAPITable API


Programmatically perform an UPDATE query.

See related ➞ UPDATE

Syntax

table.update(
    spec: UpdateSpec | Callback
): Promise<UpdateResult>;
Param Interfaces Description
spec UpdateSpec The update spec. Can be Callback—a callback function that recieves the underlying UpdateStatement instance for manipulation.

UpdateSpec

interface UpdateSpec {
    data?: Data;
    set?: any[][];
    where?: WhereClause;
    returning?: Field[];
}
Param Interfaces Description
data? Data An optional key/value data object.
set? - An optional array of key/value assignments. Required if data is not specified.
where? WhereClause An optional WHERE clause.
returning? Field Optional list of fields to return from the updated records.

UpdateResult

type UpdateResult = number | Array<object> | object;
Type Interfaces Description
number - The default update result—a number indicating the number of records updated.
Array<object> - The default update result when a RETURNING clause is specified—an array of objects representing the updated records.
object - The update result when a RETURNING clause is specified in combination with a find-one condition—an object representing the updated record.

Usage

Update all records:

await table.update({
    data: { updated_at: new Date }, 
    where: true
});

See more ➞ UPDATE

Find One

Find by ID—with actual ID name automatically figured by Linked QL:

await table.select({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: 4
});

Returning Records

Return the just updated records (array):

const updatedRecords = await table.update({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: { eq: ['email', { value: 'johndoe@example.com' }] },
    returning: '*'
});

Return the just updated record (object):

const updatedRecord = await table.update({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: 4,
    returning: '*'
});
Clone this wiki locally