Skip to content

Commit c1e37e1

Browse files
author
Burcu Dogan
committed
Merge pull request #93 from rakyll/pagination
datastore: Avoid clearing offset when start cursor is set
2 parents 5ab9b59 + f713590 commit c1e37e1

4 files changed

Lines changed: 3 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,9 @@ Pagination allows you to set an offset, limit and starting cursor to a query.
210210

211211
~~~~ js
212212
var q = ds.createQuery('Company')
213-
.offset(100) // start from 101th result
214-
.limit(10) // return only 10 results
215213
.start(cursorToken); // continue to retrieve results from the given cursor.
214+
.offset(100) // start from the 101th result after start cursor.
215+
.limit(10) // return only 10 results
216216
~~~~
217217

218218
#### Allocating IDs (ID generation)

lib/datastore/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Transaction.prototype.runQuery = function(q, opt_callback) {
219219
}
220220
var nextQuery = null;
221221
if (resp.batch.endCursor && resp.batch.endCursor != q.startVal) {
222-
nextQuery = q.start(resp.batch.endCursor);
222+
nextQuery = q.start(resp.batch.endCursor).offset(0);
223223
}
224224
opt_callback(null, entity.formatArray(resp.batch.entityResults), nextQuery);
225225
});

lib/datastore/query.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ Query.prototype.select = function(fieldNames) {
7676
Query.prototype.start = function(start) {
7777
var q = util.extend(this, new Query());
7878
q.startVal = start;
79-
q.offsetVal = 0;
8079
return q;
8180
}
8281

test/datastore.query.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,6 @@ describe('Query', function() {
112112
done();
113113
});
114114

115-
it('should reset the offset to 0 when using start tokens', function(done) {
116-
var q = ds.createQuery(['kind1']).offset(5);
117-
q.start('startVal');
118-
assert.strictEqual(q.offsetVal, 0);
119-
done();
120-
});
121-
122115
it('should be converted to a query proto successfully', function(done) {
123116
var q = ds.createQuery(['Kind'])
124117
.select(['name', 'count'])

0 commit comments

Comments
 (0)