SurrealDB Docs Logo

Enter a search query

.insert_relation()

Inserts one or multiple relations in the database.

Method Syntax
async db.insert<T>(table, data)

Arguments

ArgumentsDescription
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

Example usage

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), }, ]);

Translated query

This function will run the following query in the database.

INSERT RELATION INTO $table $data;

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install