watch method
Execute a read query every time the source tables are modified.
Use throttle to specify the minimum interval between queries. It can
also be set to null, in which case the stream will only be throttled
when its subscription is paused. watchUnthrottled can also be used to
make that more explicit.
Source tables are automatically detected using EXPLAIN QUERY PLAN.
Implementation
Stream<sqlite.ResultSet> watch(
String sql, {
List<Object?> parameters = const [],
Duration? throttle = const Duration(milliseconds: 30),
Iterable<String>? triggerOnTables,
}) {
Stream<sqlite.ResultSet> watchInner(Iterable<String> trigger) {
return onChange(
trigger,
throttle: throttle,
triggerImmediately: true,
).asyncMap((_) => getAll(sql, parameters));
}
if (triggerOnTables case final knownTrigger?) {
return watchInner(knownTrigger);
} else {
return Stream.fromFuture(getSourceTables(this, sql, parameters))
.asyncExpand(watchInner);
}
}