@@ -296,10 +296,40 @@ Query.prototype.offset = function(n) {
296296 * query.run(function(err, entities, info) {});
297297 *
298298 * //-
299- * // If you omit the callback, you will get the matching entities in a readable
300- * // object stream.
299+ * // A keys-only query returns just the keys of the result entities instead of
300+ * // the entities themselves, at lower latency and cost.
301+ * //-
302+ * query.select('__key__');
303+ *
304+ * query.run(function(err, entities) {
305+ * var keys = entities.map(function(entity) {
306+ * return entity[datastore.KEY];
307+ * });
308+ * });
309+ *
310+ * //-
311+ * // If the callback is omitted, we'll return a Promise.
301312 * //-
302- * query.run()
313+ * query.run().then(function(data) {
314+ * var entities = data[0];
315+ * });
316+ */
317+ Query . prototype . run = function ( ) {
318+ var query = this ;
319+ var args = [ query ] . concat ( [ ] . slice . call ( arguments ) ) ;
320+
321+ return this . scope . runQuery . apply ( this . scope , args ) ;
322+ } ;
323+
324+ /**
325+ * Run the query as a readable object stream.
326+ *
327+ * @param {object= } options - Optional configuration. See
328+ * {module:datastore/query#run} for a complete list of options.
329+ * @return {stream }
330+ *
331+ * @example
332+ * query.runStream()
303333 * .on('error', console.error)
304334 * .on('data', function (entity) {})
305335 * .on('info', function(info) {})
@@ -311,28 +341,16 @@ Query.prototype.offset = function(n) {
311341 * // If you anticipate many results, you can end a stream early to prevent
312342 * // unnecessary processing and API requests.
313343 * //-
314- * query.run ()
315- * .on('data', function(entity) {
344+ * query.runStream ()
345+ * .on('data', function (entity) {
316346 * this.end();
317347 * });
318- *
319- * //-
320- * // A keys-only query returns just the keys of the result entities instead of
321- * // the entities themselves, at lower latency and cost.
322- * //-
323- * query.select('__key__');
324- *
325- * query.run(function(err, entities) {
326- * var keys = entities.map(function(entity) {
327- * return entity[datastore.KEY];
328- * });
329- * });
330348 */
331- Query . prototype . run = function ( ) {
349+ Query . prototype . runStream = function ( ) {
332350 var query = this ;
333351 var args = [ query ] . concat ( [ ] . slice . call ( arguments ) ) ;
334352
335- return this . scope . runQuery . apply ( this . scope , args ) ;
353+ return this . scope . runQueryStream . apply ( this . scope , args ) ;
336354} ;
337355
338356module . exports = Query ;
0 commit comments