-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
361317d
commit f4cc5f0
Showing
1 changed file
with
141 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |