@@ -988,28 +988,26 @@ Query.prototype.testCursorPaging = function (callback) {
988
988
datastore . createQuery = this . datastore . createQuery ;
989
989
990
990
// [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.
995
994
var query = datastore . createQuery ( 'Task' )
996
- . autoPaginate ( false )
997
995
. limit ( pageSize )
998
996
. start ( pageCursor ) ;
999
997
1000
- datastore . runQuery ( query , function ( err , results , nextQuery ) {
998
+ this . datastore . runQuery ( query , function ( err , results , info ) {
1001
999
if ( err ) {
1002
1000
// An error occurred while running the query.
1003
1001
return ;
1004
1002
}
1005
1003
1006
1004
var nextPageCursor ;
1007
1005
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 ;
1013
1011
} else {
1014
1012
// No more results exist.
1015
1013
}
@@ -1018,14 +1016,14 @@ Query.prototype.testCursorPaging = function (callback) {
1018
1016
// [END cursor_paging]
1019
1017
1020
1018
delete datastore . createQuery ;
1021
- this . datastore . runQuery ( query , function ( err , results , nextQuery ) {
1019
+ this . datastore . runQuery ( query , function ( err , results , info ) {
1022
1020
if ( err ) {
1023
1021
callback ( err ) ;
1024
1022
return ;
1025
1023
}
1026
1024
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.' ) ) ;
1029
1027
} else {
1030
1028
callback ( ) ;
1031
1029
}
0 commit comments