@@ -12,6 +12,7 @@ import '../../transaction.dart';
1212import '../bindings/bindings.dart' ;
1313import '../bindings/data_visitor.dart' ;
1414import '../bindings/helpers.dart' ;
15+ import '../observable.dart' ;
1516
1617part 'builder.dart' ;
1718
@@ -611,14 +612,28 @@ class _ConditionGroupAll extends _ConditionGroup {
611612/// Use [property] to only return values or an aggregate of a single Property.
612613class Query <T > {
613614 final Pointer <OBX_query > _cQuery;
614- final Store store; // TODO make private
615+ final Store _store;
615616 final EntityDefinition <T > _entity;
616617
617618 int get entityId => _entity.model.id.id;
618619
619- Query ._(this .store , Pointer <OBX_query_builder > cBuilder, this ._entity)
620+ Query ._(this ._store , Pointer <OBX_query_builder > cBuilder, this ._entity)
620621 : _cQuery = checkObxPtr (C .query (cBuilder), 'create query' );
621622
623+ /// Create a stream, executing [Query.find()] whenever there's a change to any
624+ /// of the objects in the queried Box.
625+ /// TODO consider removing, see issue #195
626+ @Deprecated ('use query.stream instead; '
627+ 'see https://github.com/objectbox/objectbox-dart/issues/195' )
628+ Stream <List <T >> findStream () => stream.map ((q) => q.find ());
629+
630+ /// The stream gets notified whenever there's a change in any of the objects
631+ /// in the queried Box (regardless of the filter conditions).
632+ ///
633+ /// You can use the given [Query] object to run any of its operation,
634+ /// e.g. find(), count(), execute a [property()] query
635+ Stream <Query <T >> get stream => _store.subscribe <T >().map ((_) => this );
636+
622637 /// Configure an [offset] for this query.
623638 ///
624639 /// All methods that support offset will return/process Objects starting at
@@ -676,12 +691,12 @@ class Query<T> {
676691 T ? findFirst () {
677692 T ? result;
678693 final visitor = DataVisitor ((Pointer <Uint8 > dataPtr, int length) {
679- result = _entity.objectFromFB (store , dataPtr.asTypedList (length));
694+ result = _entity.objectFromFB (_store , dataPtr.asTypedList (length));
680695 return false ; // we only want to visit the first element
681696 });
682697
683698 try {
684- store .runInTransaction (TxMode .read, () {
699+ _store .runInTransaction (TxMode .read, () {
685700 checkObx (C .query_visit (_cQuery, visitor.fn, visitor.userData));
686701 });
687702 } finally {
@@ -706,9 +721,9 @@ class Query<T> {
706721
707722 /// Finds Objects matching the query.
708723 List <T > find () {
709- final collector = ObjectCollector <T >(store , _entity);
724+ final collector = ObjectCollector <T >(_store , _entity);
710725 try {
711- store .runInTransaction (
726+ _store .runInTransaction (
712727 TxMode .read,
713728 () => checkObx (
714729 C .query_visit (_cQuery, collector.fn, collector.userData)));
0 commit comments