Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update gcloud-node datastore snippets #31

Merged
merged 1 commit into from
Nov 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious, is this the right way to get these built in the docs?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't a great way to do this. However as it was these will all get included as code, rather than markdown. Instead I'll copy your markdown directly into the docs manually.

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