• Start

Methods

live

The live() method for the SurrealDB Swift SDK subscribes to changes via a live query.

Subscribes to changes on a table and returns an `AsyncStream>` of events.

Important

Live queries require the WebSocket client.

Method Syntax
try await client.live(query)

Arguments

Description

query

A live query built with

SurrealDSL.live(_:)

or the

#live

macro.

let stream = try await client.live(SurrealDSL.live(Person.self))

for await event in stream {
    switch event.action {
    case .create:
        print("Created:", event.decoded as Any)
    case .update:
        print("Updated:", event.decoded as Any)
    case .delete:
        print("Deleted record:", event.recordID)
    case .killed:
        print("Live query was killed")
    }
}

See Live queries for a full walkthrough, and kill to stop a subscription.

Was this page helpful?