.upsert()
This method can be used to insert records into the database, or to update them if they exist.
Method Syntaxdb.upsert<T,U>(thing, data)
Arguments | Description | ||
---|---|---|---|
thing required | The table name or the specific | ||
data optional | The document / record data to update. |
type Person = { id: string; name: string; settings: { active: boolean; marketing: boolean; }; }; // Upsert all records in a table const multiple = await db.upsert<Person>( 'person', { name: 'Mary Doe', settings: { active: true, marketing: false, }, } ); // Upsert a record with a specific ID const single = await db.upsert<Person>( new RecordId('person', 'john-doe'), { name: 'John Doe', settings: { active: true, marketing: true, }, } ); // The content you upsert might differ from the return type const partial = await db.upsert< Person, Pick<Person, 'name'> >( new RecordId('person', 'jane-doe'), { name: 'Jane Doe', } );