Skip to content

Commit c164175

Browse files
committed
added query condition between() for integers
1 parent 835c59a commit c164175

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

objectbox/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ This is a 1.0 release candidate - please try it out and give us any last-minute
1111
* Query conditions `inside()` renamed to `oneOf()`, `notIn()` and `notInList()` renamed to `notOneOf()`.
1212
* Query `stream` and `findStream()` are replaced by `QueryBuilder.watch()`, i.e. `box.query(...).watch()`.
1313
* New Query `stream()` to stream objects all the while the query is executed in the background.
14+
* New Query condition `between()` for integers and IDs.
1415
* Store `subscribe<EntityType>()` renamed to `watch()`.
1516
* Store `subscribeAll()` replaced by a shared broadcast stream `entityChanges`.
1617
* Entities can now contain `final` fields and they're properly stored/loaded (must be constructor params).

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,28 +126,31 @@ class QueryByteVectorProperty<EntityT>
126126
class QueryIntegerProperty<EntityT> extends QueryProperty<EntityT, int> {
127127
QueryIntegerProperty(ModelProperty model) : super(model);
128128

129-
Condition<EntityT> _op(int p, _ConditionOp cop) =>
130-
_IntegerCondition<EntityT, int>(cop, this, p, 0);
129+
Condition<EntityT> _op(_ConditionOp cop, int p1, [int p2 = 0]) =>
130+
_IntegerCondition<EntityT, int>(cop, this, p1, p2);
131131

132132
Condition<EntityT> _opList(List<int> list, _ConditionOp cop) =>
133133
_IntegerListCondition<EntityT>(cop, this, list);
134134

135-
Condition<EntityT> equals(int p) => _op(p, _ConditionOp.eq);
135+
Condition<EntityT> equals(int p) => _op(_ConditionOp.eq, p);
136136

137-
Condition<EntityT> notEquals(int p) => _op(p, _ConditionOp.notEq);
137+
Condition<EntityT> notEquals(int p) => _op(_ConditionOp.notEq, p);
138138

139-
Condition<EntityT> greaterThan(int p) => _op(p, _ConditionOp.gt);
139+
Condition<EntityT> greaterThan(int p) => _op(_ConditionOp.gt, p);
140140

141-
Condition<EntityT> greaterOrEqual(int p) => _op(p, _ConditionOp.greaterOrEq);
141+
Condition<EntityT> greaterOrEqual(int p) => _op(_ConditionOp.greaterOrEq, p);
142142

143-
Condition<EntityT> lessThan(int p) => _op(p, _ConditionOp.lt);
143+
Condition<EntityT> lessThan(int p) => _op(_ConditionOp.lt, p);
144144

145-
Condition<EntityT> lessOrEqual(int p) => _op(p, _ConditionOp.lessOrEq);
145+
Condition<EntityT> lessOrEqual(int p) => _op(_ConditionOp.lessOrEq, p);
146146

147147
Condition<EntityT> operator <(int p) => lessThan(p);
148148

149149
Condition<EntityT> operator >(int p) => greaterThan(p);
150150

151+
Condition<EntityT> between(int p1, int p2) =>
152+
_op(_ConditionOp.between, p1, p2);
153+
151154
Condition<EntityT> oneOf(List<int> list) => _opList(list, _ConditionOp.oneOf);
152155

153156
Condition<EntityT> notOneOf(List<int> list) =>

objectbox/test/query_test.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,18 @@ void main() {
180180
[q0, qany0, qany1, qany2, qany3, qall0].forEach((q) => q.close());
181181
});
182182

183+
test('between ints', () {
184+
box.putMany(<TestEntity>[
185+
TestEntity(tInt: 1),
186+
TestEntity(tInt: 3),
187+
TestEntity(tInt: 5),
188+
TestEntity(tInt: 7),
189+
TestEntity(tInt: 9)
190+
]);
191+
192+
expect(box.query(TestEntity_.tInt.between(3, 7)).build().count(), 3);
193+
});
194+
183195
test('.count matches of `greater` and `less`', () {
184196
box.putMany(<TestEntity>[
185197
TestEntity(tLong: 1336, tString: 'mord'),

0 commit comments

Comments
 (0)