• Start

API Reference

/

Features & Events

Features & Events

Transport feature flags and connection lifecycle events in the SurrealDB Kotlin SDK.

The SDK exposes the capabilities of the active transport as a set of SurrealFeature values, and the lifecycle of the connection as a stream of SurrealConnectionEvent.

Source: surrealdb.kotlin

Import
import com.surrealdb.kotlin.SurrealFeature
import com.surrealdb.kotlin.engine.SurrealConnectionEvent

An enum of the features a transport may support. Inspect the active set via the features property, or check a single feature with .supports().

Value

Available on

LiveQueries

WebSocket

Transactions

WebSocket

Sessions

WebSocket

RefreshTokens

WebSocket

ExportImport

WebSocket, HTTP

SurrealML

WebSocket, HTTP

Example
if (client.supports(SurrealFeature.LiveQueries)) {
    val subscription = client.live("person")
}

A sealed class emitted on the client's connectionEvents SharedFlow.

Variant

Payload

Description

Connecting

A connection attempt has started.

Connected

The connection is established.

Disconnected

The connection has dropped.

Reconnectingattempt: Int

,

delayMillis: Long

A reconnect is scheduled.

Errorcause: Throwable

A connection error occurred.

Example
client.connectionEvents.collect { event ->
    when (event) {
        is SurrealConnectionEvent.Connected -> println("connected")
        is SurrealConnectionEvent.Reconnecting -> println("attempt ${event.attempt}")
        is SurrealConnectionEvent.Error -> println("error: ${event.cause.message}")
        else -> {}
    }
}

Was this page helpful?