stream method
Create a reactive stream that emits query results and re-emits whenever the underlying tables change.
The first emission contains the current results. Subsequent emissions occur after any write that modifies tables the query depends on.
Streams are deduplicated: multiple calls with the same SQL and params share a single underlying query. New listeners receive the cached result immediately.
Implementation
Stream<List<Map<String, Object?>>> stream(
String sql, [
List<Object?> parameters = const [],
]) {
final key = _streamKey(sql, parameters);
// Check for existing stream with same query.
final existing = _entries[key];
if (existing != null) {
return _subscribe(existing);
}
// No existing stream — register, subscribe, run initial query.
return _createStream(key, sql, parameters);
}