• Start

Languages

/

Kotlin

/

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().

ValueAvailable on
LiveQueriesWebSocket
TransactionsWebSocket
SessionsWebSocket
RefreshTokensWebSocket
ExportImportWebSocket, HTTP
SurrealMLWebSocket, HTTP

Example

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

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

VariantPayloadDescription
ConnectingA connection attempt has started.
ConnectedThe connection is established.
DisconnectedThe connection has dropped.
Reconnectingattempt: Int, delayMillis: LongA reconnect is scheduled.
Errorcause: ThrowableA 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?