Subscribe to real-time data changes with reactive watch queries
db.query.watch()
API instead (see Incremental Watch Queries below).WatchedQuery
class that comes with a better API in that it includes loading, fetching and error states, supports multiple listeners, automatic cleanup on PowerSync close, and the new updateSettings()
API for dynamic parameter changes. This is the preferred approach for JavaScript SDKs:differentialWatch()
method uses a DEFAULT_ROW_COMPARATOR
. This comparator identifies (keys) each row by its id
column if present, or otherwise by the JSON string of the entire row. For row comparison, it uses the JSON string representation of the full row. This approach is generally safe and effective for most queries.
For some queries, performance could be improved by supplying a custom rowComparator
. Such as comparing by a hash
column generated or stored in SQLite. These hashes currently require manual implementation.
WatchedQuery
ClassWatchedQuery
class. This class, along with a new query
method allows building instances of WatchedQuery
s via the watch
and differentialWatch
methods:
updateSchema
.updateSettings
API for dynamic parameter updates (see below).WatchedQuery
instances can be shared across components:
useWatchedQuerySubscription
hook. This is ideal for global state management, query caching, or when multiple components need to subscribe to the same data: