Skip to content

Commit 41da628

Browse files
committed
merge Streamable into Query to get access to _store
1 parent a8ccf9e commit 41da628

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

objectbox/lib/src/native/observable.dart

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:typed_data';
66
import '../modelinfo/entity_definition.dart';
77
import 'bindings/bindings.dart';
88
import 'bindings/helpers.dart';
9-
import 'query/query.dart';
109
import 'store.dart';
1110

1211
/// Simple wrapper used below in ObservableStore to reduce code duplication.
@@ -129,18 +128,3 @@ extension ObservableStore on Store {
129128
return observer.stream;
130129
}
131130
}
132-
133-
/// Streamable adds stream support to queries.
134-
extension Streamable<T> on Query<T> {
135-
/// Create a stream, executing [Query.find()] whenever there's a change to any
136-
/// of the objects in the queried Box.
137-
/// TODO consider removing, see issue #195
138-
Stream<List<T>> findStream() => stream.map((q) => q.find());
139-
140-
/// The stream gets notified whenever there's a change in any of the objects
141-
/// in the queried Box (regardless of the filter conditions).
142-
///
143-
/// You can use the given [Query] object to run any of its operation,
144-
/// e.g. find(), count(), execute a [property()] query
145-
Stream<Query<T>> get stream => store.subscribe<T>().map((_) => this);
146-
}

objectbox/lib/src/native/query/query.dart

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import '../../transaction.dart';
1212
import '../bindings/bindings.dart';
1313
import '../bindings/data_visitor.dart';
1414
import '../bindings/helpers.dart';
15+
import '../observable.dart';
1516

1617
part '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.
612613
class 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

Comments
 (0)