Skip to content

Commit

Permalink
Fix hasMore not fetching datastore cursor (#77)
Browse files Browse the repository at this point in the history
* Fix hasMore not fetching datastore cursor

* Remove magic string + use separate datastore library

* Fix optional-gce
  • Loading branch information
Ace Nassri committed Oct 13, 2016
1 parent 28d1c18 commit bec07f3
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 24 deletions.
6 changes: 3 additions & 3 deletions 2-structured-data/books/model-datastore.js
Expand Up @@ -13,11 +13,11 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');

// [START config]
var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -98,7 +98,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 2-structured-data/package.json
Expand Up @@ -41,6 +41,7 @@
"body-parser": "^1.15.2",
"express": "^4.14.0",
"gcloud": "~0.37.0",
"@google-cloud/datastore": "^0.1.1",
"jade": "^1.11.0",
"kerberos": "^0.0.21",
"lodash": "^4.14.2",
Expand Down
6 changes: 3 additions & 3 deletions 3-binary-data/books/model-datastore.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -95,7 +95,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 3-binary-data/package.json
Expand Up @@ -41,6 +41,7 @@
"body-parser": "^1.15.2",
"express": "^4.14.0",
"gcloud": "~0.37.0",
"@google-cloud/datastore": "^0.1.1",
"jade": "^1.11.0",
"kerberos": "^0.0.21",
"lodash": "^4.14.2",
Expand Down
8 changes: 4 additions & 4 deletions 4-auth/books/model-datastore.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -95,7 +95,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand All @@ -113,7 +113,7 @@ function listBy (userId, limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 4-auth/package.json
Expand Up @@ -43,6 +43,7 @@
"express": "^4.14.0",
"express-session": "^1.14.0",
"gcloud": "~0.37.0",
"@google-cloud/datastore": "^0.1.1",
"jade": "^1.11.0",
"kerberos": "^0.0.21",
"lodash": "^4.14.2",
Expand Down
8 changes: 4 additions & 4 deletions 5-logging/books/model-datastore.js
Expand Up @@ -13,10 +13,10 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -95,7 +95,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand All @@ -112,7 +112,7 @@ function listBy (userId, limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 5-logging/package.json
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@google/cloud-debug": "^0.8.3",
"@google/cloud-trace": "^0.5.5",
"@google-cloud/datastore": "^0.1.1",
"body-parser": "^1.15.2",
"connect-memcached": "^0.2.0",
"express": "^4.14.0",
Expand Down
8 changes: 4 additions & 4 deletions 6-pubsub/books/model-datastore.js
Expand Up @@ -13,11 +13,11 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');
var background = require('../lib/background');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -96,7 +96,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand All @@ -113,7 +113,7 @@ function listBy (userId, limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 6-pubsub/package.json
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@google/cloud-debug": "^0.8.3",
"@google/cloud-trace": "^0.5.5",
"@google-cloud/datastore": "^0.1.1",
"async": "^2.0.1",
"body-parser": "^1.15.2",
"connect-memcached": "^0.2.0",
Expand Down
8 changes: 4 additions & 4 deletions 7-gce/books/model-datastore.js
Expand Up @@ -13,11 +13,11 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');
var background = require('../lib/background');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down Expand Up @@ -96,7 +96,7 @@ function list (limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand All @@ -113,7 +113,7 @@ function listBy (userId, limit, token, cb) {
if (err) {
return cb(err);
}
var hasMore = entities.length === limit ? nextQuery.startVal : false;
var hasMore = nextQuery.moreResults !== Datastore.NO_MORE_RESULTS ? nextQuery.endCursor : false;
cb(null, entities.map(fromDatastore), hasMore);
});
}
Expand Down
1 change: 1 addition & 0 deletions 7-gce/package.json
Expand Up @@ -40,6 +40,7 @@
"dependencies": {
"@google/cloud-debug": "^0.8.3",
"@google/cloud-trace": "^0.5.5",
"@google-cloud/datastore": "^0.1.1",
"async": "^2.0.1",
"body-parser": "^1.15.2",
"connect-memcached": "^0.2.0",
Expand Down
4 changes: 2 additions & 2 deletions optional-container-engine/books/model-datastore.js
Expand Up @@ -13,11 +13,11 @@

'use strict';

var gcloud = require('gcloud');
var Datastore = require('@google-cloud/datastore');
var config = require('../config');
var background = require('../lib/background');

var ds = gcloud.datastore({
var ds = Datastore({
projectId: config.get('GCLOUD_PROJECT')
});
var kind = 'Book';
Expand Down
1 change: 1 addition & 0 deletions optional-container-engine/package.json
Expand Up @@ -42,6 +42,7 @@
"dependencies": {
"@google/cloud-debug": "^0.8.1",
"@google/cloud-trace": "^0.5.1",
"@google-cloud/datastore": "^0.1.1",
"async": "^1.5.2",
"body-parser": "^1.15.0",
"connect-memcached": "^0.2.0",
Expand Down

0 comments on commit bec07f3

Please sign in to comment.