• Start

API Reference

/

Core

LiveQuerySubscription

The subscription handle returned by live queries in the SurrealDB Kotlin SDK.

LiveQuerySubscription is returned by .live(). It exposes a coroutine Flow of notifications and a method to stop the subscription. See Live queries for the concept.

Source: surrealdb.kotlin

Import
import com.surrealdb.kotlin.live.LiveQuerySubscription

The server-assigned live query ID.

Type: String

A flow of SurrealLiveNotification events for this subscription.

**Type:** `Flow`

Example
subscription.events.collect { event ->
    println("${event.action}: ${event.result}")
}

Stops the subscription and kills the underlying live query on the server.

Method Syntax
subscription.cancel()

Returns: Unit

The payload emitted on the events flow.

Import
import com.surrealdb.kotlin.model.SurrealLiveNotification

Field

Type

Description

actionString

The change kind:

"CREATE"

,

"UPDATE"

, or

"DELETE"

.

liveQueryIdString

The ID of the originating live query.

resultJsonElement

The changed record or diff.

Was this page helpful?