SurrealDB Docs Logo

Enter a search query

Run SurrealQL queries

The methods below are used to interact with the database and perform CRUD operations. You can also use the query method to run SurrealQL statements against the database.

MethodDescription
db.query()Runs a set of SurrealQL statements against the database
db.query_raw()Runs a set of SurrealQL statements against the database and returns the raw RPC response

.query()

Runs a set of SurrealQL statements against the database.

Method Syntax
db.query(query, vars)

Arguments

ArgumentsDescription
query required

Specifies the SurrealQL statements.

vars optional

Assigns variables which can be used in the query.

Example usage

# Assign the variable on the connection db.query( 'CREATE person SET name = "John"; SELECT * FROM type::table($tb);', { "tb": 'person' } )

.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.