From 814dd75449572e046020f3cc2df0fa0de837d057 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 4 Aug 2014 17:13:16 -0700 Subject: [PATCH 1/2] datastore: Improving confusing pagination sample on README. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 8c5254a6b27..60f2b6590c6 100644 --- a/README.md +++ b/README.md @@ -210,9 +210,9 @@ Pagination allows you to set an offset, limit and starting cursor to a query. ~~~~ js var q = ds.createQuery('Company') - .offset(100) // start from 101th result - .limit(10) // return only 10 results .start(cursorToken); // continue to retrieve results from the given cursor. + .offset(100) // start from the 101th result after start cursor. + .limit(10) // return only 10 results ~~~~ #### Allocating IDs (ID generation) From f7135908b1318ee482f601db5ccc4b6a1cb3bff6 Mon Sep 17 00:00:00 2001 From: Burcu Dogan Date: Mon, 4 Aug 2014 17:14:01 -0700 Subject: [PATCH 2/2] datastore: Don't clear the offset value, API supports cases where both offset and start cursor is set. --- lib/datastore/index.js | 2 +- lib/datastore/query.js | 1 - test/datastore.query.js | 7 ------- 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/lib/datastore/index.js b/lib/datastore/index.js index c64c3099cf7..46ab7ca3313 100644 --- a/lib/datastore/index.js +++ b/lib/datastore/index.js @@ -219,7 +219,7 @@ Transaction.prototype.runQuery = function(q, opt_callback) { } var nextQuery = null; if (resp.batch.endCursor && resp.batch.endCursor != q.startVal) { - nextQuery = q.start(resp.batch.endCursor); + nextQuery = q.start(resp.batch.endCursor).offset(0); } opt_callback(null, entity.formatArray(resp.batch.entityResults), nextQuery); }); diff --git a/lib/datastore/query.js b/lib/datastore/query.js index ac7b7f5a7a8..01230d31484 100644 --- a/lib/datastore/query.js +++ b/lib/datastore/query.js @@ -76,7 +76,6 @@ Query.prototype.select = function(fieldNames) { Query.prototype.start = function(start) { var q = util.extend(this, new Query()); q.startVal = start; - q.offsetVal = 0; return q; } diff --git a/test/datastore.query.js b/test/datastore.query.js index 1b72f33c481..33d370a59be 100644 --- a/test/datastore.query.js +++ b/test/datastore.query.js @@ -112,13 +112,6 @@ describe('Query', function() { done(); }); - it('should reset the offset to 0 when using start tokens', function(done) { - var q = ds.createQuery(['kind1']).offset(5); - q.start('startVal'); - assert.strictEqual(q.offsetVal, 0); - done(); - }); - it('should be converted to a query proto successfully', function(done) { var q = ds.createQuery(['Kind']) .select(['name', 'count'])