.create()
Creates a record in the database.
Method Syntaxdb.create<T,U>(thing, data)
Arguments | Description | ||
---|---|---|---|
thing required | The table name or a | ||
data optional | The document / record data to create. |
type Person = { id: string; name: string; settings: { active: boolean; marketing: boolean; }; }; // Create a record with a random ID const [person] = await db.create<Person>('person'); // Create a record with a specific ID const person = await db.create<Person>(new RecordId('person', 'tobie'), { name: 'Tobie', settings: { active: true, marketing: true, }, }); // The content you are creating the record with might differ from the return type const [record] = await db.create< Person, Pick<Person, 'name'> >( new RecordId('person', 'tobie'), { name: 'Tobie', } );
This function will run the following query in the database.
CREATE $thing CONTENT $data;