- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2
table.update()
        Oxford Harrison edited this page Nov 19, 2024 
        ·
        10 revisions
      
    Programmatically perform an UPDATE query.
See related ➞
UPDATE
table.update(
    spec: UpdateSpec | Callback
): Promise<UpdateResult>;| Param | Interfaces | Description | 
|---|---|---|
| spec | UpdateSpec | The update spec. Can be Callback—a callback function that recieves the underlyingUpdateStatementinstance for manipulation. | 
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 datais not specified. | 
| where? | WhereClause | An optional WHEREclause. | 
| 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 RETURNINGclause is specified—an array of objects representing the updated records. | 
| object | - | The update result when a RETURNINGclause is specified in combination with a find-one condition—an object representing the updated record. | 
Update all records:
await table.update({
    data: { updated_at: new Date }, 
    where: true
});See more ➞
UPDATE
Find by ID—with actual ID name automatically figured by Linked QL:
await table.select({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: 4
});Return the just updated records (array):
const updatedRecords = await table.update({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: { eq: ['email', { value: '[email protected]' }] },
    returning: '*'
});Return the just updated record (object):
const updatedRecord = await table.update({
    data: {
        first_name: 'John',
        last_name: 'Doe'
    },
    where: 4,
    returning: '*'
});