diff --git a/example/flutter/objectbox_demo/lib/main.dart b/example/flutter/objectbox_demo/lib/main.dart index bfca2245..0339e14c 100644 --- a/example/flutter/objectbox_demo/lib/main.dart +++ b/example/flutter/objectbox_demo/lib/main.dart @@ -59,12 +59,8 @@ class ViewModel { _box = Box(_store); final dateProp = Note_.date; - final dummyCondition = dateProp.greaterThan(0); - _query = _box - .query(dummyCondition) - .order(dateProp, flags: Order.descending) - .build(); + _query = _box.emptyQuery.order(dateProp, flags: Order.descending).build(); } void addNote(Note note) => _box.put(note); diff --git a/lib/src/bindings/signatures.dart b/lib/src/bindings/signatures.dart index 57de4390..a0bbf70f 100644 --- a/lib/src/bindings/signatures.dart +++ b/lib/src/bindings/signatures.dart @@ -259,3 +259,10 @@ typedef obx_bytes_array_set_t = Ret Function( SizeT index, Pointer data, SizeT size); + +/* // TODO + obx_qb_bytes_eq_dart_t obx_qb_bytes_equal; + obx_qb_bytes_lt_gt_dart_t obx_qb_bytes_greater, obx_qb_bytes_less; + + obx_qb_param_alias_dart_t obx_qb_param_alias; +*/ diff --git a/lib/src/box.dart b/lib/src/box.dart index 12eacb29..e9f472eb 100644 --- a/lib/src/box.dart +++ b/lib/src/box.dart @@ -257,6 +257,10 @@ class Box { } } + /// When no conditions are required on properties + QueryBuilder get emptyQuery => + QueryBuilder(_store, _fbManager, _modelEntity.id.id); + /// Returns true if no objects are in this box. bool isEmpty() { final isEmpty = allocate(); diff --git a/lib/src/query/builder.dart b/lib/src/query/builder.dart index ffdaeb75..ff1c72d6 100644 --- a/lib/src/query/builder.dart +++ b/lib/src/query/builder.dart @@ -8,8 +8,8 @@ class QueryBuilder { Pointer _cBuilder; final OBXFlatbuffersManager _fbManager; - QueryBuilder( - this._store, this._fbManager, this._entityId, this._queryCondition); + QueryBuilder(this._store, this._fbManager, this._entityId, + [this._queryCondition]); void _throwExceptionIfNecessary() { if (bindings.obx_qb_error_code(_cBuilder) != OBXError.OBX_SUCCESS) { @@ -24,7 +24,7 @@ class QueryBuilder { Query build() { _createBuilder(); - if (0 == _queryCondition.apply(this, true)) { + if (_queryCondition != null && 0 == _queryCondition.apply(this, true)) { _throwExceptionIfNecessary(); } @@ -45,37 +45,3 @@ class QueryBuilder { return this; } } - -/* // Not done yet - obx_qb_bytes_eq_dart_t obx_qb_bytes_equal; - obx_qb_bytes_lt_gt_dart_t obx_qb_bytes_greater, obx_qb_bytes_less; - - obx_qb_param_alias_dart_t obx_qb_param_alias; -*/ - -////// -////// - -/** Inspiration - Modifier and Type Method Description - QueryBuilder backlink​(RelationInfo relationInfo) - Creates a backlink (reversed link) to another entity, for which you also can describe conditions using the returned builder. - void close() - ** QueryBuilder eager​(int limit, RelationInfo relationInfo, RelationInfo... more) - Like eager(RelationInfo, RelationInfo[]), but limits eager loading to the given count. - ** QueryBuilder eager​(RelationInfo relationInfo, RelationInfo... more) - Specifies relations that should be resolved eagerly. - ** QueryBuilder filter​(QueryFilter filter) // dart has built-in higher order functions - Sets a filter that executes on primary query results (returned from the db core) on a Java level. - QueryBuilder link​(RelationInfo relationInfo) - Creates a link to another entity, for which you also can describe conditions using the returned builder. - ** QueryBuilder order​(Property property) - Specifies given property to be used for sorting. - ** QueryBuilder order​(Property property, int flags) - Defines the order with which the results are ordered (default: none). - ** QueryBuilder orderDesc​(Property property) - Specifies given property in descending order to be used for sorting. - ** QueryBuilder parameterAlias​(java.lang.String alias) - Assigns the given alias to the previous condition. - ** QueryBuilder sort​(java.util.Comparator comparator) - */ diff --git a/test/query_test.dart b/test/query_test.dart index 408f97ad..8a079ce7 100644 --- a/test/query_test.dart +++ b/test/query_test.dart @@ -15,6 +15,23 @@ void main() { box = env.box; }); + test('Query with no conditions, and order as desc ints', () { + box.putMany([ + TestEntity(tInt: 0), + TestEntity(tInt: 10), + TestEntity(tInt: 100), + TestEntity(tInt: 10), + TestEntity(tInt: 0), + ]); + + var query = + box.emptyQuery.order(TestEntity_.tInt, flags: Order.descending).build(); + final listDesc = query.find(); + query.close(); + + expect(listDesc.map((t) => t.tInt).toList(), [100, 10, 10, 0, 0]); + }); + test('ignore transient field', () { box.put(TestEntity(tDouble: 0.1, ignore: 1337));