The CRUD methods on SurrealClient return fluent builders that compile to SurrealQL. Each builder is refined with chainable methods and terminated with await() (raw JsonElement) or the typed awaitAs<T>() extension.
Source: surrealdb.kotlin
Terminal methods
.await()
Executes the builder and returns the unwrapped result of the first statement as a JsonElement.
Returns: JsonElement
.awaitRaw()
Executes the builder and returns the raw [{ status, result, time, type }] response envelope.
Returns: JsonElement
.awaitAs<T>()
An inline extension that executes the builder and decodes the result into T using kotlinx.serialization. Available on every builder.
Returns: T
.compile()
Compiles the builder to a BoundQuery without executing it — useful for inspection or composing with .query().
Returns: BoundQuery
SelectQuery
Returned by .select(what).
| Method | Description |
|---|---|
.fields(vararg names) | Selects specific fields. |
.value(field) | Selects a single field's value. |
.where(expr) | Filters with an expression. |
.start(n) | Skips the first n records. |
.limit(n) | Limits the number of records. |
.fetch(vararg fields) | Fetches related records. |
.timeout(seconds) | Sets a query timeout. |
.version(literal) | Reads at a specific version. |
Content builders
CreateQuery, UpdateQuery, UpsertQuery, and RelateQuery accept content and a return mode.
| Method | Description |
|---|---|
.content(data) | Sets the record content (a JsonElement). |
.where(expr) | Filters affected records (update, upsert, merge, patch, delete). |
.returnMode(mode) | Controls the returned payload (see ReturnMode). |
ReturnMode
| Value | Description |
|---|---|
ReturnMode.None | Returns nothing. |
ReturnMode.Before | Returns records as they were before the change. |
ReturnMode.After | Returns records after the change. |
ReturnMode.Diff | Returns a JSON Patch diff. |
ReturnMode.Fields(names) | Returns only the named fields. |
RunQuery
Returned by .run(function).
| Method | Description |
|---|---|
.args(vararg args) | Sets the function arguments. |
.version(version) | Selects a function version. |
Expression helpers
Build WHERE expressions with the helper functions and infix operators from com.surrealdb.kotlin.query.
| Helper | SurrealQL |
|---|---|
field(name) | A validated field reference. |
value(any) | A literal value. |
raw(boundQuery) | A raw fragment. |
a eq b | = |
a neq b | != |
a lt b | < |
a lte b | <= |
a gt b | > |
a gte b | >= |
a contains b | CONTAINS |
a inside b | IN |
a and b | AND |
a or b | OR |
not(expr) | ! |
Note
surql DSL
The surql helpers build a parameterised BoundQuery with automatic, injection-safe binding of values and record identifiers.
Learn more
SurrealClient API reference for the CRUD methods
Data manipulation for the concepts
Serialization for
awaitAs