Skip to content

Commit 3b13821

Browse files
datastore: update docs to show how to get the Key
1 parent fb13f28 commit 3b13821

5 files changed

Lines changed: 36 additions & 26 deletions

File tree

packages/datastore/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ datastore.save({
5555
key: blogPostKey,
5656
data: blogPostData
5757
}).then(function() {
58-
// The blog post is not published!
58+
// The blog post is now published!
5959
});
6060

6161
// It's also possible to integrate with third-party Promise libraries.

packages/datastore/src/index.js

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ var Transaction = require('./transaction.js');
107107
* var key = datastore.key(['Company', 'Google']);
108108
*
109109
* datastore.get(key, function(err, entity) {
110-
* // entity.data = The record.
111-
* // entity.key = The key.
110+
* // entity = The record.
111+
* // entity[datastore.KEY] = The key for this entity.
112112
* });
113113
*
114114
* //-
@@ -147,13 +147,10 @@ var Transaction = require('./transaction.js');
147147
* // Run the query with {module:datastore#runQuery}.
148148
* //-
149149
* datastore.runQuery(query, function(err, entities) {
150-
* // entities = [
151-
* // {
152-
* // data: The record,
153-
* // key: The key for this record
154-
* // },
155-
* // ...
156-
* // ]
150+
* // entities = An array of records.
151+
*
152+
* // Access the Key object for an entity.
153+
* var firstEntityKey = entities[0][datastore.KEY];
157154
* });
158155
*
159156
* //-
@@ -227,11 +224,8 @@ var Transaction = require('./transaction.js');
227224
* //-
228225
* datastore.get(key, function(err, entity) {
229226
* // entity = {
230-
* // key: datastore.key(['Company', 'Google']),
231-
* // data: {
232-
* // name: 'Google',
233-
* // location: 'CA'
234-
* // }
227+
* // name: 'Google',
228+
* // location: 'CA'
235229
* // }
236230
* });
237231
*
@@ -280,16 +274,16 @@ var Transaction = require('./transaction.js');
280274
*
281275
* var key = datastore.key(['Company', 'Google']);
282276
*
283-
* transaction.get(key, function(err, data) {
277+
* transaction.get(key, function(err, entity) {
284278
* if (err) {
285279
* // Error handling omitted.
286280
* }
287281
*
288-
* data.symbol = 'GOOG';
282+
* entity.symbol = 'GOOG';
289283
*
290284
* transaction.save({
291285
* key: key,
292-
* data: data
286+
* data: entity
293287
* });
294288
*
295289
* transaction.commit(function(err) {

packages/datastore/src/query.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,12 @@ Query.prototype.offset = function(n) {
293293
* - {module:datastore#NO_MORE_RESULTS}: There are no more results.
294294
*
295295
* @example
296-
* query.run(function(err, entities, info) {});
296+
* query.run(function(err, entities, info) {
297+
* // entities = An array of records.
298+
*
299+
* // Access the Key object for an entity.
300+
* var firstEntityKey = entities[0][datastore.KEY];
301+
* });
297302
*
298303
* //-
299304
* // A keys-only query returns just the keys of the result entities instead of
@@ -331,7 +336,10 @@ Query.prototype.run = function() {
331336
* @example
332337
* query.runStream()
333338
* .on('error', console.error)
334-
* .on('data', function (entity) {})
339+
* .on('data', function (entity) {
340+
* // Access the Key object for this entity.
341+
* var key = entity[datastore.KEY];
342+
* })
335343
* .on('info', function(info) {})
336344
* .on('end', function() {
337345
* // All entities retrieved.

packages/datastore/src/request.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,12 @@ DatastoreRequest.prototype.insert = function(entities, callback) {
466466
* //-
467467
* var query = datastore.createQuery('Lion');
468468
*
469-
* datastore.runQuery(query, function(err, entities, info) {});
469+
* datastore.runQuery(query, function(err, entities, info) {
470+
* // entities = An array of records.
471+
*
472+
* // Access the Key object for an entity.
473+
* var firstEntityKey = entities[0][datastore.KEY];
474+
* });
470475
*
471476
* //-
472477
* // Or, if you're using a transaction object.
@@ -541,7 +546,10 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
541546
* @example
542547
* datastore.runQueryStream(query)
543548
* .on('error', console.error)
544-
* .on('data', function (entity) {})
549+
* .on('data', function(entity) {
550+
* // Access the Key object for this entity.
551+
* var key = entity[datastore.KEY];
552+
* })
545553
* .on('info', function(info) {})
546554
* .on('end', function() {
547555
* // All entities retrieved.
@@ -552,7 +560,7 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
552560
* // unnecessary processing and API requests.
553561
* //-
554562
* datastore.runQueryStream(query)
555-
* .on('data', function (entity) {
563+
* .on('data', function(entity) {
556564
* this.end();
557565
* });
558566
*/

packages/datastore/src/transaction.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,12 @@ Transaction.prototype.rollback = function(callback) {
348348
* // Perform Datastore transactional operations.
349349
* var key = datastore.key(['Company', 123]);
350350
*
351-
* transaction.get(key, function(err, data) {
352-
* data.name = 'Google';
351+
* transaction.get(key, function(err, entity) {
352+
* entity.name = 'Google';
353353
*
354354
* transaction.save({
355355
* key: key,
356-
* data: data
356+
* data: entity
357357
* });
358358
*
359359
* transaction.commit(function(err) {

0 commit comments

Comments
 (0)