• Start

Languages

/

Kotlin

/

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<SurrealLiveNotification>

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
FieldTypeDescription
actionStringThe change kind: "CREATE", "UPDATE", or "DELETE".
liveQueryIdStringThe ID of the originating live query.
resultJsonElementThe changed record or diff.

Was this page helpful?