LIVE SELECT statement
LIVE SELECT statement can be used to initiate a real-time selection from a table, including the option to apply filters.
In practical terms, when you execute a
LIVE SELECT query, it triggers an ongoing session that captures any subsequent changes to the data in real-time.
These changes are then immediately transmitted to the client, ensuring that the client is consistently updated with the latest data modifications.
LIVE SELECT [ [ VALUE ] @fields [ AS @alias ] | DIFF ] FROM @targets [ WHERE @conditions ] [ FETCH @fields ... ] ;
By default, SurrealDB will push the entire record over the websocket when created or updated, and just the record's ID when deleted.
LIVE SELECT * FROM person;
When using the
DIFF mode, updates will be sent in the form of an array with JSON Patch messages.
LIVE SELECT DIFF FROM person;
Filter the live query
You can optionally apply filters with the
LIVE SELECT * FROM person WHERE age > 18;