Skip to content

Commit

Permalink
datastore: update docs to show how to get the Key (#1725)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenplusplus authored and callmehiphop committed Oct 21, 2016
1 parent 474675e commit d8cbf38
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
2 changes: 1 addition & 1 deletion packages/datastore/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ datastore.save({
key: blogPostKey,
data: blogPostData
}).then(function() {
// The blog post is not published!
// The blog post is now published!
});

// It's also possible to integrate with third-party Promise libraries.
Expand Down
28 changes: 11 additions & 17 deletions packages/datastore/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ var Transaction = require('./transaction.js');
* var key = datastore.key(['Company', 'Google']);
*
* datastore.get(key, function(err, entity) {
* // entity.data = The record.
* // entity.key = The key.
* // entity = The record.
* // entity[datastore.KEY] = The key for this entity.
* });
*
* //-
Expand Down Expand Up @@ -147,13 +147,10 @@ var Transaction = require('./transaction.js');
* // Run the query with {module:datastore#runQuery}.
* //-
* datastore.runQuery(query, function(err, entities) {
* // entities = [
* // {
* // data: The record,
* // key: The key for this record
* // },
* // ...
* // ]
* // entities = An array of records.
*
* // Access the Key object for an entity.
* var firstEntityKey = entities[0][datastore.KEY];
* });
*
* //-
Expand Down Expand Up @@ -227,11 +224,8 @@ var Transaction = require('./transaction.js');
* //-
* datastore.get(key, function(err, entity) {
* // entity = {
* // key: datastore.key(['Company', 'Google']),
* // data: {
* // name: 'Google',
* // location: 'CA'
* // }
* // name: 'Google',
* // location: 'CA'
* // }
* });
*
Expand Down Expand Up @@ -280,16 +274,16 @@ var Transaction = require('./transaction.js');
*
* var key = datastore.key(['Company', 'Google']);
*
* transaction.get(key, function(err, data) {
* transaction.get(key, function(err, entity) {
* if (err) {
* // Error handling omitted.
* }
*
* data.symbol = 'GOOG';
* entity.symbol = 'GOOG';
*
* transaction.save({
* key: key,
* data: data
* data: entity
* });
*
* transaction.commit(function(err) {
Expand Down
12 changes: 10 additions & 2 deletions packages/datastore/src/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,12 @@ Query.prototype.offset = function(n) {
* - {module:datastore#NO_MORE_RESULTS}: There are no more results.
*
* @example
* query.run(function(err, entities, info) {});
* query.run(function(err, entities, info) {
* // entities = An array of records.
*
* // Access the Key object for an entity.
* var firstEntityKey = entities[0][datastore.KEY];
* });
*
* //-
* // A keys-only query returns just the keys of the result entities instead of
Expand Down Expand Up @@ -331,7 +336,10 @@ Query.prototype.run = function() {
* @example
* query.runStream()
* .on('error', console.error)
* .on('data', function (entity) {})
* .on('data', function (entity) {
* // Access the Key object for this entity.
* var key = entity[datastore.KEY];
* })
* .on('info', function(info) {})
* .on('end', function() {
* // All entities retrieved.
Expand Down
14 changes: 11 additions & 3 deletions packages/datastore/src/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,12 @@ DatastoreRequest.prototype.insert = function(entities, callback) {
* //-
* var query = datastore.createQuery('Lion');
*
* datastore.runQuery(query, function(err, entities, info) {});
* datastore.runQuery(query, function(err, entities, info) {
* // entities = An array of records.
*
* // Access the Key object for an entity.
* var firstEntityKey = entities[0][datastore.KEY];
* });
*
* //-
* // Or, if you're using a transaction object.
Expand Down Expand Up @@ -541,7 +546,10 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
* @example
* datastore.runQueryStream(query)
* .on('error', console.error)
* .on('data', function (entity) {})
* .on('data', function(entity) {
* // Access the Key object for this entity.
* var key = entity[datastore.KEY];
* })
* .on('info', function(info) {})
* .on('end', function() {
* // All entities retrieved.
Expand All @@ -552,7 +560,7 @@ DatastoreRequest.prototype.runQuery = function(query, options, callback) {
* // unnecessary processing and API requests.
* //-
* datastore.runQueryStream(query)
* .on('data', function (entity) {
* .on('data', function(entity) {
* this.end();
* });
*/
Expand Down
6 changes: 3 additions & 3 deletions packages/datastore/src/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ Transaction.prototype.rollback = function(callback) {
* // Perform Datastore transactional operations.
* var key = datastore.key(['Company', 123]);
*
* transaction.get(key, function(err, data) {
* data.name = 'Google';
* transaction.get(key, function(err, entity) {
* entity.name = 'Google';
*
* transaction.save({
* key: key,
* data: data
* data: entity
* });
*
* transaction.commit(function(err) {
Expand Down

0 comments on commit d8cbf38

Please sign in to comment.