.insert_relation()
Inserts one or multiple relations in the database.
Method Syntaxasync db.insert<T>(table, data)
Arguments | Description | ||
---|---|---|---|
table optional | Optionally pass along a table to insert into. | ||
data optional | Either a single document/record or an array of documents/records to insert |
type Likes = { id: RecordId<"likes">; in: RecordId<"person">; out: RecordId<"post">; }; // Insert a single record const [person] = await db.insert_relation<Likes>('likes', { in: new RecordId('person', 'tobie'), out: new RecordId('post', 123), }); // Insert multiple records across tables const people = await db.insert<Likes>('likes', [ { in: new RecordId('person', 'tobie'), out: new RecordId('post', 123), }, { in: new RecordId('person', 'jaime'), out: new RecordId('post', 456), }, ]);
This function will run the following query in the database.
INSERT RELATION INTO $table $data;