Skip to content

Commit

Permalink
add datastore v1beta3 snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus committed Oct 14, 2015
1 parent 361317d commit f4cc5f0
Showing 1 changed file with 141 additions and 0 deletions.
141 changes: 141 additions & 0 deletions datastore/concepts.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
'use strict';

var gcloud = require('gcloud')({
projectId: process.env.TEST_PROJECT_ID
});

var datastore = gcloud.datastore();

// [START Entities:incomplete_key]
var task_key = datastore.key('Task');
// [END Entities:incomplete_key]

// [START Entities:named_key]
var task_key = datastore.key([
'Task',
'sampletask'
]);
// [END Entities:named_key]

// [START Entities:key_with_parent]
var task_key = datastore.key([
'TaskList',
'default',
'Task',
'sampleTask'
]);
// [END Entities:key_with_parent]

// [START Entities:key_with_multilevel_parent]
var task_key = datastore.key([
'User',
'alice',
'TaskList',
'default',
'Task',
'sampleTask'
]);
// [END Entities:key_with_multilevel_parent]

// [START Consistency:entity_with_parent]
var task = {
key: datastore.key(['TaskList', 'default', 'Task', 'sampleTask']),
data: {
type: 'Personal',
done: false,
priority: 4,
description: 'Learn Cloud Datastore'
}
};
// [END Consistency:entity_with_parent]

// [START Entities:properties]
var taskData = {
type: 'Personal',
done: false,
priority: 4,
percent_complete: 10.0,
description: 'Learn Cloud Datastore'
};
// [END Entities:properties]

// [START Entities:array_value]
var taskData = {
tags: [
'fun',
'programming'
],
collaborators: [
'alice',
'bob'
]
};
// [END Entities:array_value]

// [START Entities:basic_entity]
var task = {
type: 'Personal',
done: false,
priority: 4,
description: 'Learn Cloud Datastore'
};
// [END Entities:basic_entity]

// [START Entities:upsert]
datastore.upsert({
key: task_key,
data: task
}, function(err) {});
// [END Entities:upsert]

// [START Entities:insert]
datastore.insert({
key: task_key,
data: task
}, function(err) {});
// [END Entities:insert]

// [START Entities:lookup]
datastore.get(task_key, function(err, entity) {});
// [End Entities:lookup]

// [START Entities:update]
datastore.update({
key: task_key,
data: task
}, function(err) {});
// [END Entities:update]

// [START Entities:delete]
datastore.delete({
key: task_key,
data: task
}, function(err) {});
// [END Entities:delete]

// [START Entities:batch_upsert]
datastore.upsert([
{
key: task_key1,
data: task1
},
{
key: task_key2
data: task2
}
], function(err) {});
// [END Entities:batch_upsert]

// [START Entities:batch_lookup]
datastore.get([
task_key1,
task_key2
], function(err, entities) {});
// [END Entities:batch_lookup]

// [START Entities:batch_delete]
datastore.delete([
task_key1,
task_key2
], function(err) {});
// [END Entities:batch_delete]

0 comments on commit f4cc5f0

Please sign in to comment.