# LiveQuerySubscription

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

`LiveQuerySubscription` is returned by [`.live()`](/docs/reference/kotlin/api/core/surreal-client.md#live). It exposes a coroutine [`Flow`](https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/-flow/) of notifications and a method to stop the subscription. See [Live queries](/docs/reference/kotlin/concepts/live-queries.md) for the concept.

**Source:** [surrealdb.kotlin](https://github.com/surrealdb/surrealdb.kotlin)

```kotlin title="Import"
import com.surrealdb.kotlin.live.LiveQuerySubscription
```

---

## Members

### `id` {#id}

The server-assigned live query ID.

**Type:** `String`

### `events` {#events}

A flow of [`SurrealLiveNotification`](#notification) events for this subscription.

**Type:** `Flow<SurrealLiveNotification>`

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

### `.cancel()` {#cancel}

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

```kotlin title="Method Syntax"
subscription.cancel()
```

**Returns:** `Unit`

---

## `SurrealLiveNotification` {#notification}

The payload emitted on the [`events`](#events) flow.

```kotlin title="Import"
import com.surrealdb.kotlin.model.SurrealLiveNotification
```

<table>
    <thead>
        <tr><th>Field</th><th>Type</th><th>Description</th></tr>
    </thead>
    <tbody>
        <tr><td><code>action</code></td><td><code>String</code></td><td>The change kind: <code>"CREATE"</code>, <code>"UPDATE"</code>, or <code>"DELETE"</code>.</td></tr>
        <tr><td><code>liveQueryId</code></td><td><code>String</code></td><td>The ID of the originating live query.</td></tr>
        <tr><td><code>result</code></td><td><code>JsonElement</code></td><td>The changed record or diff.</td></tr>
    </tbody>
</table>

## Learn more

- [Live queries](/docs/reference/kotlin/concepts/live-queries.md)
- [SurrealClient API reference](/docs/reference/kotlin/api/core/surreal-client.md) for `.live()` and `.kill()`
