SurrealDB
SurrealDB Docs Logo

Enter a search query

Navigation

Query Builders

Query builder classes are promise-like objects returned by query methods on SurrealQueryable. They provide chainable configuration methods before executing the query.

All query builders implement a promise-like interface, allowing you to await them directly or chain configuration methods before execution.

Common Pattern

// Chain configuration before awaiting const users = await db.select(new Table('users')) .where('age > 18') .limit(10) .start(0); // Or await directly const user = await db.select(new RecordId('users', 'john'));

Query Builder Classes

Core Query Execution

  • Query - Execute raw SurrealQL with streaming and batch processing support

Record Operations

Graph Operations

Real-time & Advanced

Common Configuration Options

Most query builders support these common configuration methods:

.json()

Return results as JSON strings instead of parsed objects.

const jsonString = await db.select(new Table('users')).json();

.timeout(duration)

Set a timeout for the query operation.

await db.select(new Table('users'))
    .timeout(new Duration('5s'));

.version(timestamp)

Query records at a specific version/timestamp (time-travel queries).

await db.select(new Table('users'))
    .version(new DateTime('2024-01-01T00:00:00Z'));

Type Parameters

Query builders use generic type parameters for type safety:

  • T - The base type of the record
  • I - The input type for operations
  • J - The JSON string type when using .json()
  • R - The result type (for Query class)

See Also