• Start

Languages

/

Kotlin

/

API Reference

/

Core

SurrealSession

The SurrealSession class exposes querying and authentication with isolated per-session state.

SurrealSession is the base class of SurrealClient and the type returned by .newSession(). It exposes the full querying, authentication, and CRUD API with state — authentication, namespace, database, and parameters — isolated to that session. See Multiple sessions for the concept.

Source: surrealdb.kotlin

Because SurrealClient extends SurrealSession, every session — root or child — provides the same methods documented on the client:

MethodTypeDescription
.namespace()String?The session's current namespace.
.database()String?The session's current database.
.accessToken()String?The session's current access token, if authenticated.

Example

val session = client.newSession()
session.signin(buildJsonObject { put("user", "a"); put("pass", "a") })
session.use("acme", "main")

// ... use the session ...

client.closeSession(session)

Transactions are started on a session via the transaction { } and beginTransaction() extension functions. See the Transaction reference.

Was this page helpful?