-
-
Notifications
You must be signed in to change notification settings - Fork 2
table.update()
Oxford Harrison edited this page Nov 15, 2024
·
10 revisions
Programmatically perform an UPDATE
query.
See related ➞
UPDATE
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. |
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. |
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. |
Update all records:
// { where: true } being a good practice
await table.update(
{ updated_at: new Date },
{ where: true }
);
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 }
);
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: ['*'] }
);
See ➞ Magic Paths