watch method

  1. @override
Stream<List<$ActiveDataclass>> watch({
  1. bool distinct = false,
  2. int? limit,
  3. int? offset,
})
override

Creates an auto-updating stream of the result that emits new items whenever any table used in this statement changes.

Use limit and offset to limit the number of rows returned An offset will only be applied if a limit is also set

The distinct parameter (disabled by default) controls whether to generate a SELECT DISTINCT query, removing duplicates from the result.

Implementation

@override
Stream<List<$ActiveDataclass>> watch(
    {bool distinct = false, int? limit, int? offset}) {
  /// Build a select statement so we can extract the tables that should be watched
  var baseSelect = $state.prefetchHooks
      .withJoins($state)
      .copyWith(distinct: distinct, limit: limit, offset: offset)
      .buildSelectStatement();
  final context = GenerationContext.fromDb($state.db);
  baseSelect.writeInto(context);

  return $state.db.createStream(QueryStreamFetcher(
    readsFrom: TableUpdateQuery.onAllTables([
      ...context.watchedTables,
      ...$state.prefetchHooks.explicitlyWatchedTables
    ]),
    fetchData: () async {
      return get(distinct: distinct, limit: limit, offset: offset);
    },
  ));
}