• Start
Sign In

Concepts

Value types

Work with record identifiers, tables, and the JSON value model in the SurrealDB Kotlin SDK.

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.

TypeDescription
TableRefers to a table by name
RecordIdRefers to a single record (table:id)
RecordIdRangeRefers 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.

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)
}
Note

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.

Was this page helpful?