watch method

Stream<List<R>> watch({
  1. required Iterable<String> tables,
  2. MssqlWatchStrategy strategy = MssqlWatchStrategy.polling,
  3. Duration interval = const Duration(seconds: 1),
  4. MssqlChangeHub? hub,
})

Re-runs this projection when tables may have changed.

A projection has no table identity of its own. tables must name the objects whose writes should invalidate it.

Implementation

Stream<List<R>> watch({
  required Iterable<String> tables,
  MssqlWatchStrategy strategy = MssqlWatchStrategy.polling,
  Duration interval = const Duration(seconds: 1),
  MssqlChangeHub? hub,
}) {
  final watched = tables.toSet();
  if (watched.isEmpty) {
    throw ArgumentError.value(
      tables,
      'tables',
      'A projection watch needs explicit table names; the SELECT list '
          'does not name its sources.',
    );
  }
  return mssqlWatchRows<R>(
    strategy: strategy,
    interval: interval,
    tables: watched,
    hub: hub,
    read: get,
    same: (a, b) {
      if (a.length != b.length) return false;
      for (var i = 0; i < a.length; i++) {
        if (a[i] != b[i]) return false;
      }
      return true;
    },
  );
}