.merge()
Modifies all records in a table, or a specific record, in the database.
Method Syntaxasync db.merge<T,U>(thing, data)
NoteThis function merges the current document / record data with the specified data.
Arguments | Description | ||
---|---|---|---|
thing required | The table name or the specific | ||
data optional | The document / record data to merge. |
type Person = { id: string; name: string; updated_at: Date; settings: { active: boolean; marketing: boolean; }; }; // Update all records in a table const people = await db.merge<Person>('person', { updated_at: new Date(), }); // Update a record with a specific ID const person = await db.merge<Person>(new RecordId('person', 'tobie'), { updated_at: new Date(), settings: { active: true, }, }); // The content you are merging the record with might differ from the return type const record = await db.merge< Person, Pick<Person, 'name'> >(new RecordId('person', 'tobie'), { name: 'Tobie', });
This function will run the following query in the database.
UPDATE $thing MERGE $data;