Skip to content

Commit

Permalink
Merge pull request #31 from pcostell/master
Browse files Browse the repository at this point in the history
Update gcloud-node datastore snippets
  • Loading branch information
jmdobry committed Nov 18, 2015
2 parents 175cb0c + 5a4fd8e commit aac4192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
26 changes: 8 additions & 18 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ Entity.prototype.testLookup = function(callback) {
// };
}
});
// [End lookup]
// [END lookup]

this.datastore.insert({
key: taskKey,
Expand Down Expand Up @@ -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]);

Expand All @@ -355,6 +354,7 @@ Entity.prototype.testBatchUpsert = function(callback) {
description: 'Integrate Cloud Datastore'
};

// [START batch_upsert]
datastore.upsert([
{
key: taskKey1,
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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;
};
Expand Down Expand Up @@ -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);
};
Expand Down
12 changes: 7 additions & 5 deletions datastore/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

'use strict';

var gcloud = require('gcloud');
var input = process.argv.splice(2);
var command = input.shift();

Expand All @@ -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).
Expand Down Expand Up @@ -61,7 +64,6 @@ export DATASTORE_PROJECT_ID=<project-id>
```sh
npm run tasks
```
// [END build_service]
*/

// [START add_entity]
Expand Down Expand Up @@ -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',
Expand All @@ -139,7 +141,7 @@ function deleteTask(taskId, callback) {

datastore.delete(taskKey, callback);
}
// [END delete_task]
// [END delete_entity]

// [START format_results]
function formatTasks(tasks) {
Expand Down

0 comments on commit aac4192

Please sign in to comment.