Skip to content

Commit

Permalink
https://github.com/GoogleCloudPlatform/nodejs-docs-samples/pull/16#di…
Browse files Browse the repository at this point in the history
…scussion_r42408072
  • Loading branch information
stephenplusplus committed Oct 19, 2015
1 parent fc90126 commit 61fbb61
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions datastore/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,47 @@ Query.prototype.testKindlessQuery = function(callback) {
};

Query.prototype.testRunQueryProjection = function(callback) {
var self = this;
var query = this.projectionQuery;

// jshint unused:false
// Overwrite the mock to actually run the query.
datastore.runQuery = function(query, queryCallback) {
// Restore the mock.
datastore.runQuery = function() {};

self.datastore.runQuery(query, function(err) {
if (err) {
callback(err);
return;
}

queryCallback.apply(null, arguments);

if (priorities.length === 0 || percentCompletes.length === 0) {
callback(new Error('Projection lists did not build up.'));
} else {
callback();
}
});
};

// jshint unused:false, camelcase:false
// [START run_query_projection]
datastore.runQuery(query, function(err, entities) {
if (!err) {
// Entities found.
var priorities = [];
var percentCompletes = [];

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

tasks.forEach(function(task) {
priorities.push(task.data.priority);
percentCompletes.push(task.data.percent_complete);
});
});
// [END run_query_projection]

this.datastore.runQuery(query, callback);
};

Query.prototype.testKeysOnlyQuery = function(callback) {
Expand Down

0 comments on commit 61fbb61

Please sign in to comment.