Skip to content

Commit f23d3d5

Browse files
Merge pull request #903 from callmehiphop/docs
Documentation bug fixes
2 parents 6ceb711 + 9009e8d commit f23d3d5

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

lib/datastore/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,15 @@ Datastore.dataset = Dataset;
110110
* server (usually "http://localhost:8080").
111111
* @param {string} options.namespace - Namespace to isolate transactions to.
112112
* @return {module:datastore/dataset}
113+
*
114+
* @example
115+
* var gcloud = require('gcloud')({
116+
* keyFilename: '/path/to/keyfile.json',
117+
* projectId: 'my-project'
118+
* });
119+
*
120+
* var datastore = gcloud.datastore;
121+
* var dataset = datastore.dataset();
113122
*/
114123
Datastore.prototype.dataset = function(options) {
115124
options = options || {};

lib/datastore/query.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,25 @@ function Query(namespace, kinds) {
7575
}
7676

7777
/**
78+
* @param {boolean=} autoPaginateVal - Have pagination handled automatically.
79+
* Default: true.
7880
* @return {module:datastore/query}
81+
*
82+
* @example
83+
* // Retrieve a list of people related to person "1234",
84+
* // disabling auto pagination
85+
* var query = dataset.createQuery('Person')
86+
* .hasAncestor(dataset.key(['Person', 1234]))
87+
* .autoPaginate(false);
88+
*
89+
* var callback = function(err, entities, nextQuery, apiResponse) {
90+
* if (nextQuery) {
91+
* // More results might exist, so we'll manually fetch them
92+
* dataset.runQuery(nextQuery, callback);
93+
* }
94+
* };
95+
*
96+
* dataset.runQuery(query, callback);
7997
*/
8098
Query.prototype.autoPaginate = function(autoPaginateVal) {
8199
this.autoPaginateVal = autoPaginateVal !== false;

lib/datastore/request.js

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,15 @@ function DatastoreRequest() {}
118118
*
119119
* @example
120120
* //-
121-
* // Where you see `transaction`, assume this is the context that's relevant to
122-
* // your use, whether that be a Dataset or Transaction object.
121+
* // Get a single entity.
123122
* //-
123+
* var key = dataset.key(['Company', 123]);
124+
*
125+
* dataset.get(key, function(err, entity) {});
124126
*
125127
* //-
126-
* // Get a single entity.
128+
* // Or, if you're using a transaction object.
127129
* //-
128-
* var key = dataset.key(['Company', 123]);
129130
*
130131
* transaction.get(key, function(err, entity) {});
131132
*
@@ -137,12 +138,12 @@ function DatastoreRequest() {}
137138
* dataset.key(['Product', 'Computer'])
138139
* ];
139140
*
140-
* transaction.get(keys, function(err, entities) {});
141+
* dataset.get(keys, function(err, entities) {});
141142
*
142143
* //-
143144
* // Or, get the entities as a readable object stream.
144145
* //-
145-
* transaction.get(keys)
146+
* dataset.get(keys)
146147
* .on('error', function(err) {})
147148
* .on('data', function(entity) {
148149
* // entity is an entity object.
@@ -483,16 +484,18 @@ DatastoreRequest.prototype.save = function(entities, callback) {
483484
* @param {object} callback.apiResponse - The full API response.
484485
*
485486
* @example
487+
* dataset.delete(dataset.key(['Company', 123]), function(err, apiResp) {});
488+
*
486489
* //-
487-
* // Where you see `transaction`, assume this is the context that's relevant to
488-
* // your use case, whether that be a Dataset or a Transaction object.
490+
* // Or, if you're using a transaction object.
489491
* //-
490492
*
491-
* // Delete a single entity.
492493
* transaction.delete(dataset.key(['Company', 123]), function(err, apiResp) {});
493494
*
495+
* //-
494496
* // Delete multiple entities at once.
495-
* transaction.delete([
497+
* //-
498+
* dataset.delete([
496499
* dataset.key(['Company', 123]),
497500
* dataset.key(['Product', 'Computer'])
498501
* ], function(err, apiResponse) {});
@@ -555,11 +558,13 @@ DatastoreRequest.prototype.delete = function(keys, callback) {
555558
* //-
556559
* var query = dataset.createQuery('Lion');
557560
*
558-
* transaction.runQuery(query, function(err, entities) {
559-
* if (!err) {
560-
* // Handle entities here.
561-
* }
562-
* });
561+
* dataset.runQuery(query, function(err, entities) {});
562+
*
563+
* //-
564+
* // Or, if you're using a transaction object.
565+
* //-
566+
*
567+
* transaction.runQuery(query, function(err, entities) {});
563568
*
564569
* //-
565570
* // To control how many API requests are made and page through the results
@@ -574,14 +579,14 @@ DatastoreRequest.prototype.delete = function(keys, callback) {
574579
* }
575580
* };
576581
*
577-
* transaction.runQuery(manualPageQuery, callback);
582+
* dataset.runQuery(manualPageQuery, callback);
578583
*
579584
* //-
580585
* // If you omit the callback, runQuery will automatically call subsequent
581586
* // queries until no results remain. Entity objects will be pushed as they are
582587
* // found.
583588
* //-
584-
* transaction.runQuery(query)
589+
* dataset.runQuery(query)
585590
* .on('error', console.error)
586591
* .on('data', function (entity) {})
587592
* .on('end', function() {
@@ -594,7 +599,7 @@ DatastoreRequest.prototype.delete = function(keys, callback) {
594599
* //-
595600
* var keysOnlyQuery = dataset.createQuery('Lion').select('__key__');
596601
*
597-
* transaction.runQuery(keysOnlyQuery, function(err, entities) {
602+
* dataset.runQuery(keysOnlyQuery, function(err, entities) {
598603
* // entities[].key = Key object
599604
* // entities[].data = Empty object
600605
* });
@@ -644,15 +649,16 @@ DatastoreRequest.prototype.runQuery = function(query, callback) {
644649
* @param {object} callback.apiResponse - The full API response.
645650
*
646651
* @example
647-
* //-
648-
* // Where you see `transaction`, assume this is the context that's relevant to
649-
* // your use, whether that be a Dataset or a Transaction object.
650-
* //-
651-
*
652652
* var incompleteKey = dataset.key(['Company']);
653653
*
654654
* // The following call will create 100 new IDs from the Company kind, which
655655
* // exists under the default namespace.
656+
* dataset.allocateIds(incompleteKey, 100, function(err, keys) {});
657+
*
658+
* //-
659+
* // Or, if you're using a transaction object.
660+
* //-
661+
*
656662
* transaction.allocateIds(incompleteKey, 100, function(err, keys) {});
657663
*
658664
* // You may prefer to create IDs from a non-default namespace by providing an
@@ -664,7 +670,7 @@ DatastoreRequest.prototype.runQuery = function(query, callback) {
664670
* path: ['Company']
665671
* });
666672
* var callback = function(err, keys, apiResponse) {};
667-
* transaction.allocateIds(incompleteKey, 100, callback);
673+
* dataset.allocateIds(incompleteKey, 100, callback);
668674
*/
669675
DatastoreRequest.prototype.allocateIds = function(incompleteKey, n, callback) {
670676
if (entity.isKeyComplete(incompleteKey)) {

0 commit comments

Comments
 (0)