The Kotlin SDK represents data with kotlinx.serialization JSON values, plus a small set of dedicated types for referring to tables and records. These are the building blocks passed to the CRUD builders and queries.
Record and table types
| Type | Description |
|---|---|
Table | Refers to a table by name |
RecordId | Refers to a single record (table:id) |
RecordIdRange | Refers to a range of records within a table |
import com.surrealdb.kotlin.query.RecordId
import com.surrealdb.kotlin.query.Table
val table = Table("person")
val record = RecordId("person", "ada")When these are bound into a query, the SDK renders them with the appropriate SurrealDB casting functions — type::table(name) for a Table and type::record(table, id) for a RecordId — so values are always passed safely.
The JSON value model
Beyond the record types above, all data is modelled as JsonElement. Read methods return a JsonElement, and write methods accept a JsonObject. Build payloads with buildJsonObject.
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put
val data = buildJsonObject {
put("name", "Ada")
put("age", 36)
} The SDK does not ship dedicated wrapper classes for datetimes, durations, or geometries. Express these as SurrealQL literals in a query, or as the JSON values that SurrealDB expects, and decode results into your own @Serializable types.
Learn more
Table,RecordId, andRecordIdRangereferencesValue (JSON model) reference
Serialization for decoding into your own types