watch method

  1. @override
Stream<ResultSet> watch(
  1. String sql, {
  2. List<Object?> parameters = const [],
  3. Duration throttle = const Duration(milliseconds: 30),
  4. Iterable<String>? triggerOnTables,
})
override

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<sqlite.ResultSet> watch(String sql,
    {List<Object?> parameters = const [],
    Duration throttle = const Duration(milliseconds: 30),
    Iterable<String>? triggerOnTables}) {
  assert(updates != null,
      'updates stream must be provided to allow query watching');

  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);
  }
}