SurrealQueryable
The SurrealQueryable class is an abstract base class that provides all query execution methods for interacting with SurrealDB. It is the foundation for executing database operations and is extended by SurrealSession and SurrealTransaction.
Extended by: SurrealSession, SurrealTransaction
Source: api/queryable.ts
Properties
api
Access user-defined API endpoints. This property returns a SurrealApi instance for invoking custom database APIs.
You can provide type definitions for type-safe API calls.
Type: SurrealApi<TPaths>
Examples:
Query Methods
.query()
Execute raw SurrealQL statements against the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
query | string | BoundQuery | The SurrealQL query string or BoundQuery instance. |
bindings | Record<string, unknown> | Variables to bind in the query (when using string query). |
Type Parameters
R extends unknown[]- Array of result types for each query statement
Returns
Query<R> - A query instance that can be configured and executed
Examples
.select()
Select records from the database by record ID, record ID range, or table.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | RecordId | A specific record ID to select. |
range | RecordIdRange | A range of record IDs to select. |
table | Table | A table to select all records from. |
Returns
SelectPromise<T> - A promise with chainable configuration methods
Examples
.create()
Create new records in the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | RecordId | The record ID for the new record. |
table | Table | The table to create a record in (auto-generated ID). |
Returns
CreatePromise<T> - A promise with chainable configuration methods
Examples
.insert()
Insert one or multiple records into the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
table | Table | The table to insert records into. |
data | T | T[] | One or more records to insert. |
Returns
InsertPromise<T> - A promise with chainable configuration methods
Examples
.update()
Update existing records in the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | RecordId | A specific record ID to update. |
range | RecordIdRange | A range of record IDs to update. |
table | Table | A table to update all records in. |
Returns
UpdatePromise<T> - A promise with chainable configuration methods
Examples
.upsert()
Upsert records (insert if they don't exist, replace if they do).
Warning
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | RecordId | A specific record ID to upsert. |
range | RecordIdRange | A range of record IDs to upsert. |
table | Table | A table to upsert all records in. |
Returns
UpsertPromise<T> - A promise with chainable configuration methods
Example
.delete()
Delete records from the database.
Parameters
| Parameter | Type | Description |
|---|---|---|
recordId | RecordId | A specific record ID to delete. |
range | RecordIdRange | A range of record IDs to delete. |
table | Table | A table to delete all records from. |
Returns
DeletePromise<T> - A promise with chainable configuration methods
Examples
.relate()
Create graph relationships (edges) between records.
Parameters
| Parameter | Type | Description |
|---|---|---|
from | RecordId | RecordId[] | The source record(s) for the relationship. |
edge | Table | RecordId | The edge table or specific edge record ID. |
to | RecordId | RecordId[] | The target record(s) for the relationship. |
data | Partial<T> | Optional data to store on the edge record. |
Returns
RelatePromise<T> - A promise for the relationship operation
Examples
.live()
Create a live query subscription to receive real-time updates when records change.
Parameters
| Parameter | Type | Description |
|---|---|---|
what | LiveResource | The table, record ID, or range to subscribe to. |
Returns
ManagedLivePromise<T> - A managed live query subscription
Example
.liveOf()
Subscribe to an existing live query using its ID.
Note
Parameters
| Parameter | Type | Description |
|---|---|---|
id | Uuid | The UUID of the existing live query. |
Returns
UnmanagedLivePromise - An unmanaged live query subscription
Example
.run()
Execute a SurrealDB function or SurrealML model.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The full name of the function to run (e.g., "fn::calculate"). |
version | string | The version of a SurrealML model to use. |
args | unknown[] | Arguments to pass to the function. |
Returns
RunPromise<T> - A promise for the function result
Examples
.auth()
Get the currently authenticated record user by selecting the $auth parameter.
Note
Returns
AuthPromise<T> - A promise for the authenticated user record
Example
See Also
SurrealSession - Session management extending this class
SurrealTransaction - Transaction support extending this class
Query Builders - Detailed query builder documentation
SelectPromise - SELECT query configuration
CreatePromise - CREATE query configuration