Skip to content

API Reference

/

Features & Events

Features & Events

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, against SurrealDB 3.x or earlier. SurrealDB 4.0 removed SurrealML.

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?