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

DOCSAPITable API


Programmatically perform an UPDATE query.

See related ➞ UPDATE

Syntax

table.update(
    entry: Entry,
    modifiers?: UpdateOptions | Callback,
): Promise<UpdateResult>;
Param Interfaces Description
entry Entry A key/value data object.
modifiers? UpdateOptions Optional additional query modifiers. Can be Callback—a callback function that recieves the underlying UpdateStatement instance for manipulation.

UpdateOptions

interface UpdateOptions {
    where?: WhereClause;
    returning?: Field[];
}
Param Interfaces Description
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

Call pattern

Update all records:

// { where: true } being a good practice
await table.update(
    { updated_at: new Date }, 
    { where: true }
);

Find one

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

/**
 * UPDATE ...
 * WHERE automatically_figured_primary_key_name = 4
 */
await table.select(
    { first_name: 'John', last_name: 'Doe' },
    { where: 4 }
);

Returning records

Return the just updated records (array):

// Update all records that match and return all
const updatedRecords = await table.update(
    { first_name: 'John', last_name: 'Doe' },
    { where: {
        eq: ['email', { value: '[email protected]' }]
    }, returning: ['*'] }
);

Return the just updated record (object):

// A "find-one" condition
const updatedRecord = await table.update(
    { first_name: 'John', last_name: 'Doe' },
    { where: 4, returning: ['*'] }
);

Multi-dimensional update

See ➞ Magic Paths

Clone this wiki locally