Skip to content

Commit 1a07340

Browse files
author
Burcu Dogan
committed
Merge pull request #94 from rakyll/endcursor
datastore: Add support for end cursors
2 parents c1e37e1 + bbe4141 commit 1a07340

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed

lib/datastore/entity.js

+3
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,9 @@ var queryToQueryProto = function(q) {
304304
if (q.startVal) {
305305
query.startCursor = q.startVal;
306306
}
307+
if (q.endVal) {
308+
query.endCursor = q.endVal;
309+
}
307310
if (q.offsetVal > 0) {
308311
query.offset = q.offsetVal;
309312
}

lib/datastore/query.js

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function Query(namespace, kinds) {
2727

2828
// pagination
2929
this.startVal = null;
30+
this.endVal = null;
3031
this.limitVal = -1;
3132
this.offsetVal = -1;
3233
}
@@ -79,6 +80,12 @@ Query.prototype.start = function(start) {
7980
return q;
8081
}
8182

83+
Query.prototype.end = function(end) {
84+
var q = util.extend(this, new Query());
85+
q.endVal = end;
86+
return q;
87+
};
88+
8289
Query.prototype.limit = function(n) {
8390
var q = util.extend(this, new Query());
8491
q.limitVal = n;

test/datastore.query.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,12 @@ describe('Query', function() {
106106
done();
107107
});
108108

109-
it('should allow page start tokens', function(done) {
110-
var q = ds.createQuery(['kind1']).start('abc123');
109+
it('should allow page start and end tokens', function(done) {
110+
var q = ds.createQuery(['kind1'])
111+
.start('abc123')
112+
.end('def987');
111113
assert.strictEqual(q.startVal, 'abc123');
114+
assert.strictEqual(q.endVal, 'def987');
112115
done();
113116
});
114117

@@ -119,7 +122,8 @@ describe('Query', function() {
119122
.filter('name =', 'Burcu')
120123
.order('-count')
121124
.groupBy(['count'])
122-
.start('cursor')
125+
.start('start-cursor')
126+
.end('end-cursor')
123127
.offset(5)
124128
.limit(10);
125129
assert.deepEqual(entity.queryToQueryProto(q), queryProto);

test/testdata/proto_query.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"projection":[{"property":{"name":"name"}},{"property":{"name":"count"}}],"kinds":[{"name":"Kind"}],"filter":{"compositeFilter":{"filters":[{"propertyFilter":{"property":{"name":"count"},"operator":"GREATER_THAN_OR_EQUAL","value":{"integerValue":5}}},{"propertyFilter":{"property":{"name":"name"},"operator":"EQUAL","value":{"stringValue":"Burcu"}}}],"operator":"AND"}},"order":[{"property":{"name":"count"},"direction":"DESCENDING"}],"groupBy":[{"name":"count"}],"startCursor":"cursor","offset":5,"limit":10}
1+
{"projection":[{"property":{"name":"name"}},{"property":{"name":"count"}}],"kinds":[{"name":"Kind"}],"filter":{"compositeFilter":{"filters":[{"propertyFilter":{"property":{"name":"count"},"operator":"GREATER_THAN_OR_EQUAL","value":{"integerValue":5}}},{"propertyFilter":{"property":{"name":"name"},"operator":"EQUAL","value":{"stringValue":"Burcu"}}}],"operator":"AND"}},"order":[{"property":{"name":"count"},"direction":"DESCENDING"}],"groupBy":[{"name":"count"}],"startCursor":"start-cursor","endCursor": "end-cursor","offset":5,"limit":10}

0 commit comments

Comments
 (0)