SurrealDB Docs Logo

Enter a search query

.subscribeLive()

Registers a callback function for a running live query.

Method Syntax
async db.subscribeLive<T>(queryUuid, callback)

Arguments

ArgumentsDescription
queryUuid required

The UUID of a running live query

callback required

A callback function that processes live notifications. Consult the Live Actions for a list of all possible values being returned.

Example usage

await db.subscribeLive( queryUuid, // The callback function takes an object with the "action" and "result" properties ( action, result ) => { // action can be: "CREATE", "UPDATE", "DELETE" or "CLOSE" if (action === 'CLOSE') return; // result contains either the entire record, or a set of JSON patches when diff mode is enabled processSomeLiveQueryUpdate(result); } )

Live Actions

For CREATE, UPDATE and DELETE, the type Result is the generic argument passed to .live() or .subscribeLive().
It extends either Record<string, unknown> or Patch.

It’s generally recommended to handle the CLOSE action first, as that clears out the type for the result parameter.

ActionResultDescription

CLOSE

killed or disconnected

Emitted when the live query is closed due to it either being killed or the connection being disconnected.

CREATE

Result

Emitted when a record within your subscription gets created

UPDATE

Result

Emitted when a record within your subscription gets updated

DELETE

Result

Emitted when a record within your subscription gets deleted

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install