Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pagination #222

Merged
merged 2 commits into from
Sep 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 12 additions & 14 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,28 +988,26 @@ Query.prototype.testCursorPaging = function (callback) {
datastore.createQuery = this.datastore.createQuery;

// [START cursor_paging]
// By default, gcloud-node will paginate through all of the results that match
// a query, push them into an array, then return them to your callback after
// they have all been retrieved. You must execute `.autoPaginate(false)` on
// your query to disable this behavior.
// By default, gcloud-node will automatically paginate through all of the
// results that match a query. However, this sample implements manual
// pagination using limits and cursor tokens.
var query = datastore.createQuery('Task')
.autoPaginate(false)
.limit(pageSize)
.start(pageCursor);

datastore.runQuery(query, function (err, results, nextQuery) {
this.datastore.runQuery(query, function (err, results, info) {
if (err) {
// An error occurred while running the query.
return;
}

var nextPageCursor;

if (nextQuery) {
// If there are more results to retrieve, the start cursor is
// automatically set on `nextQuery`. To get this value directly, access
// the `startVal` property.
nextPageCursor = nextQuery.startVal;
if (info.moreResults !== Datastore.NO_MORE_RESULTS) {
// If there are more results to retrieve, the end cursor is
// automatically set on `info`. To get this value directly, access
// the `endCursor` property.
nextPageCursor = info.endCursor;
} else {
// No more results exist.
}
Expand All @@ -1018,14 +1016,14 @@ Query.prototype.testCursorPaging = function (callback) {
// [END cursor_paging]

delete datastore.createQuery;
this.datastore.runQuery(query, function (err, results, nextQuery) {
this.datastore.runQuery(query, function (err, results, info) {
if (err) {
callback(err);
return;
}

if (!nextQuery || !nextQuery.startVal) {
callback(new Error('A nextQuery with a startVal is not present.'));
if (!info || !info.endCursor) {
callback(new Error('An `info` with an `endCursor` is not present.'));
} else {
callback();
}
Expand Down
2 changes: 1 addition & 1 deletion datastore/system-test/concepts.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ describe('datastore:concepts', function () {
query.testLimit(done);
});

it.skip('allows manual pagination through results', function (done) {
it('allows manual pagination through results', function (done) {
entity.testBatchUpsert(function (err) {
assert.ifError(err);
setTimeout(function () {
Expand Down