watch method
Stream<ResultSet>
watch(
- String sql, {
- List<
Object?> parameters = const [], - Duration throttle = const Duration(milliseconds: 30),
- Iterable<
String> ? triggerOnTables,
inherited
Execute a read query every time the source tables are modified.
Use throttle
to specify the minimum interval between queries.
Source tables are automatically detected using EXPLAIN QUERY PLAN
.
Implementation
@override
Stream<ResultSet> watch(String sql,
{List<Object?> parameters = const [],
Duration throttle = const Duration(milliseconds: 30),
Iterable<String>? triggerOnTables}) {
if (triggerOnTables == null || triggerOnTables.isEmpty) {
return database.watch(sql, parameters: parameters, throttle: throttle);
}
List<String> powersyncTables = [];
for (String tableName in triggerOnTables) {
powersyncTables.add(tableName);
powersyncTables.add(_prefixTableNames(tableName, 'ps_data__'));
powersyncTables.add(_prefixTableNames(tableName, 'ps_data_local__'));
}
return database.watch(sql,
parameters: parameters,
throttle: throttle,
triggerOnTables: powersyncTables);
}