The .query() family runs raw SurrealQL and is the foundation of the SDK — the CRUD builders compile to SurrealQL and dispatch through it. Queries can be supplied as a string with a JsonObject of bound parameters, or built with the surql DSL.
API references
| Method | Description |
|---|---|
client.query(sql, vars) | Runs SurrealQL and returns the raw result |
client.queryAs<T>(sql, vars) | Runs SurrealQL and decodes the result to T |
client.queryResult(sql, vars) | Runs SurrealQL and returns a Result |
client.let(key, value) | Defines a session parameter |
client.unset(key) | Removes a session parameter |
Running a query
Pass SurrealQL and, optionally, a JsonObject of bound parameters. The result is returned as a JsonElement.
Note
Decoding results
To decode a query result straight into your own types, use the inline .queryAs<T>() helper with a @Serializable type.
You can also decode an arbitrary JsonElement yourself with .decode<T>().
Result variants
Every networked call has a ...Result companion that returns a Result instead of throwing, which is useful when you prefer to handle failures functionally.
See Error handling for the exception hierarchy thrown by the non-Result variants.
Session parameters
Define parameters that persist for the session with .let(), and remove them with .unset(). These are referenced as $name in subsequent queries.
Building queries
The surql DSL builds a parameterised BoundQuery with automatic binding of values and record identifiers.
Learn more
SurrealClient API reference for complete method signatures
Query builder reference for the fluent builders and
surqlDSLData manipulation for CRUD with the builders
Serialization for working with
@Serializabletypes