SurrealDB Docs Logo

Enter a search query

.query()

Runs a set of SurrealQL statements against the database.

Method Syntax
async db.query<T>(query, vars)

Arguments

ArgumentsDescription
query required

Specifies the SurrealQL statements.

vars optional

Assigns variables which can be used in the query.

Example usage

type Person = { id: string; name: string; }; // Assign the variable on the connection const result = await db.query<[Person[], Person[]]>( 'CREATE person SET name = "John"; SELECT * FROM type::table($tb);', { tb: 'person' } ); // Get the first result from the first query const created = result[0].result[0]; // Get all of the results from the second query const people = result[1].result;

.query_raw()

With .query_raw(), you will get back the raw RPC response. This contrast to the .query() method, this will not throw for errors that occur in individual queries, but will rather give those back as a string, and this will include the time it took to execute the individual queries.

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install