From 5a4fd8e5fce746f8be823dee050ef46bad7ef66b Mon Sep 17 00:00:00 2001 From: Patrick Costello Date: Mon, 16 Nov 2015 14:11:38 -0800 Subject: [PATCH] Fixes for Datastore gcloud-node snippets. - Correct typo in snippet region. - Installation instructions should not be in build_service snippet. - Batch ops included too much extra info. --- datastore/concepts.js | 26 ++++++++------------------ datastore/tasks.js | 12 +++++++----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/datastore/concepts.js b/datastore/concepts.js index 2ba3c25d28..0f2c6e1633 100644 --- a/datastore/concepts.js +++ b/datastore/concepts.js @@ -262,7 +262,7 @@ Entity.prototype.testLookup = function(callback) { // }; } }); - // [End lookup] + // [END lookup] this.datastore.insert({ key: taskKey, @@ -337,7 +337,6 @@ Entity.prototype.testDelete = function(callback) { Entity.prototype.testBatchUpsert = function(callback) { datastore.key = this.datastore.key; - // [START batch_upsert] var taskKey1 = datastore.key(['Task', 1]); var taskKey2 = datastore.key(['Task', 2]); @@ -355,6 +354,7 @@ Entity.prototype.testBatchUpsert = function(callback) { description: 'Integrate Cloud Datastore' }; + // [START batch_upsert] datastore.upsert([ { key: taskKey1, @@ -392,19 +392,9 @@ Entity.prototype.testBatchLookup = function(callback) { datastore.get([ taskKey1, taskKey2 - ], function(err, entities) { + ], function(err, tasks) { if (!err) { - // entities[0].data = { - // type: 'Personal', - // done: false, - // priority: 4, - // description: 'Learn Cloud Datastore' - // }; - - // entities[1].data = { - // type: 'Work', - // // ... - // }; + // Tasks retrieved successfully. } }); // [END batch_lookup] @@ -651,12 +641,12 @@ Query.prototype.getProjectionQuery = function() { Query.prototype.getAncestorQuery = function() { var datastore = this.datastore; - // [START anscestor_query] + // [START ancestor_query] var ancestorKey = datastore.key(['TaskList', 'default']); var query = datastore.createQuery('Task') .hasAncestor(ancestorKey); - // [END anscestor_query] + // [END ancestor_query] return query; }; @@ -852,11 +842,11 @@ Query.prototype.testArrayValueInequalityRange = function(callback) { Query.prototype.testArrayValueEquality = function(callback) { var datastore = this.datastore; - // [START array_value_equality_range] + // [START array_value_equality] var query = datastore.createQuery('Task') .filter('tag =', 'fun') .filter('tag =', 'programming'); - // [END array_value_equality_range] + // [END array_value_equality] this.datastore.runQuery(query, callback); }; diff --git a/datastore/tasks.js b/datastore/tasks.js index 9e0436fc44..3ee860badb 100755 --- a/datastore/tasks.js +++ b/datastore/tasks.js @@ -13,7 +13,6 @@ 'use strict'; -var gcloud = require('gcloud'); var input = process.argv.splice(2); var command = input.shift(); @@ -22,12 +21,16 @@ if (!projectId) { throw new Error('TEST_PROJECT_ID environment variable required.'); } +// [START build_service] +var gcloud = require('gcloud'); + var datastore = gcloud.datastore({ projectId: projectId }); +// [END build_service] /* -// [START build_service] +Installation and setup instructions. 1. Download the TaskList sample application from [here] (https://github.com/GoogleCloudPlatform/nodejs-docs-samples/archive/master.zip). @@ -61,7 +64,6 @@ export DATASTORE_PROJECT_ID= ```sh npm run tasks ``` -// [END build_service] */ // [START add_entity] @@ -130,7 +132,7 @@ function listTasks(callback) { } // [END retrieve_entities] -// [START delete_task] +// [START delete_entity] function deleteTask(taskId, callback) { var taskKey = datastore.key([ 'Task', @@ -139,7 +141,7 @@ function deleteTask(taskId, callback) { datastore.delete(taskKey, callback); } -// [END delete_task] +// [END delete_entity] // [START format_results] function formatTasks(tasks) {