Skip to content

Commit e6e6690

Browse files
committed
Query - mark offset and limit params deprecated, add missing tests
1 parent 89bf491 commit e6e6690

File tree

2 files changed

+23
-24
lines changed

2 files changed

+23
-24
lines changed

lib/src/query/query.dart

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ class QueryStringProperty extends QueryProperty {
9797
return _opList(list, ConditionOp.notIn, caseSensitive);
9898
}
9999

100-
/// Using [withEqual] is deprecated, use [greaterOrEqual] instead.
101100
Condition greaterThan(String p,
102-
{bool caseSensitive = false, bool withEqual = false}) {
101+
{bool caseSensitive = false,
102+
@Deprecated('Use greaterOrEqual() instead') bool withEqual = false}) {
103103
if (withEqual) {
104104
return greaterOrEqual(p, caseSensitive: caseSensitive);
105105
} else {
@@ -111,9 +111,9 @@ class QueryStringProperty extends QueryProperty {
111111
return _op(p, ConditionOp.greaterOrEq, caseSensitive);
112112
}
113113

114-
/// Using [withEqual] is deprecated, use [lessOrEqual] instead.
115114
Condition lessThan(String p,
116-
{bool caseSensitive = false, bool withEqual = false}) {
115+
{bool caseSensitive = false,
116+
@Deprecated('Use lessOrEqual() instead') bool withEqual = false}) {
117117
if (withEqual) {
118118
return lessOrEqual(p, caseSensitive: caseSensitive);
119119
} else {
@@ -589,8 +589,9 @@ class Query<T> {
589589
///
590590
/// Call with offset=0 to reset to the default behavior,
591591
/// i.e. starting from the first element.
592-
void offset(int offset) {
592+
Query<T> offset(int offset) {
593593
checkObx(bindings.obx_query_offset(_cQuery, offset));
594+
return this;
594595
}
595596

596597
/// Configure a [limit] for this query.
@@ -601,8 +602,9 @@ class Query<T> {
601602
///
602603
/// Call with limit=0 to reset to the default behavior -
603604
/// zero limit means no limit applied.
604-
void limit(int limit) {
605+
Query<T> limit(int limit) {
605606
checkObx(bindings.obx_query_limit(_cQuery, limit));
607+
return this;
606608
}
607609

608610
/// Returns the number of matching Objects.
@@ -643,10 +645,9 @@ class Query<T> {
643645
}
644646

645647
/// Finds Objects matching the query and returns their IDs.
646-
///
647-
/// [offset] and [limit] are deprecated, explicitly call
648-
/// the equally named methods.
649-
List<int> findIds({int offset = 0, int limit = 0}) {
648+
List<int> findIds(
649+
{@Deprecated('Use offset() instead') int offset = 0,
650+
@Deprecated('Use limit() instead') int limit = 0}) {
650651
if (offset > 0) {
651652
this.offset(offset);
652653
}
@@ -666,10 +667,9 @@ class Query<T> {
666667
}
667668

668669
/// Finds Objects matching the query.
669-
///
670-
/// [offset] and [limit] are deprecated, explicitly call
671-
/// the equally named methods.
672-
List<T> find({int offset = 0, int limit = 0}) {
670+
List<T> find(
671+
{@Deprecated('Use offset() instead') int offset = 0,
672+
@Deprecated('Use limit() instead') int limit = 0}) {
673673
if (offset > 0) {
674674
this.offset(offset);
675675
}

test/query_test.dart

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,20 +227,19 @@ void main() {
227227
q3.close();
228228
});
229229

230-
test('.find returns List<TestEntity>', () {
230+
test('.find offset and limit', () {
231231
box.put(TestEntity());
232-
box.put(TestEntity(tString: 'test'));
233-
box.put(TestEntity(tString: 'test'));
232+
box.put(TestEntity(tString: 'a'));
233+
box.put(TestEntity(tString: 'b'));
234+
box.put(TestEntity(tString: 'c'));
234235

235-
final text = TestEntity_.tString;
236+
var q = box.query().build();
237+
expect(q.find().length, 4);
236238

237-
var q = box.query(text.notNull()).build();
238-
expect(q.find().length, 2);
239-
q.close();
239+
expect(q.offset(2).find().map((e) => e.tString), equals(['b', 'c']));
240+
expect(q.limit(1).find().map((e) => e.tString), equals(['b']));
241+
expect(q.offset(0).find().map((e) => e.tString), equals([null]));
240242

241-
q = box.query(text.isNull()).build();
242-
q.limit(1);
243-
expect(q.find().length, 1);
244243
q.close();
245244
});
246245

0 commit comments

Comments
 (0)