Live queries push changes to your application as records are created, updated, or deleted. In the Kotlin SDK, a live subscription exposes a coroutine Flow of notifications that you collect.
Note
API references
| Method | Description |
|---|---|
client.live(table) | Starts a live query and returns a subscription |
subscription.events | A Flow of live notifications |
subscription.cancel() | Stops the subscription |
client.kill(id) | Kills a live query by ID |
Starting a live query
Call .live() with a table name to receive a LiveQuerySubscription, then collect its events flow. Each SurrealLiveNotification carries an action ("CREATE", "UPDATE", or "DELETE") and a result payload.
Pass diff = true to receive JSON Patch diffs instead of the full record.
Filtered live queries
To watch a subset of records with a WHERE clause, run a LIVE SELECT statement through .query(); the result is the live query UUID, which you can later pass to .kill().
Stopping a subscription
Cancel a subscription started with .live() by calling .cancel(), which also kills the underlying live query on the server. Cancel the collecting coroutine separately.
For live queries started via raw SurrealQL, kill them with their UUID.
Learn more
Live subscription reference for the subscription and notification types
SurrealClient API reference for
.live()and.kill()Features and events for checking transport support
LIVE SELECT for the SurrealQL statement