Skip to content

Commit 0166ac0

Browse files
author
Ace Nassri
committed
Fix pagination
1 parent ff7bda4 commit 0166ac0

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

datastore/concepts.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -988,28 +988,26 @@ Query.prototype.testCursorPaging = function (callback) {
988988
datastore.createQuery = this.datastore.createQuery;
989989

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

1000-
datastore.runQuery(query, function (err, results, nextQuery) {
998+
this.datastore.runQuery(query, function (err, results, info) {
1001999
if (err) {
10021000
// An error occurred while running the query.
10031001
return;
10041002
}
10051003

10061004
var nextPageCursor;
10071005

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

10201018
delete datastore.createQuery;
1021-
this.datastore.runQuery(query, function (err, results, nextQuery) {
1019+
this.datastore.runQuery(query, function (err, results, info) {
10221020
if (err) {
10231021
callback(err);
10241022
return;
10251023
}
10261024

1027-
if (!nextQuery || !nextQuery.startVal) {
1028-
callback(new Error('A nextQuery with a startVal is not present.'));
1025+
if (!info || !info.endCursor) {
1026+
callback(new Error('An `info` with an `endCursor` is not present.'));
10291027
} else {
10301028
callback();
10311029
}

0 commit comments

Comments
 (0)