@@ -120,6 +120,36 @@ BigQuery.prototype.createDataset = function(id, options, callback) {
120120 } ) ;
121121} ;
122122
123+ /**
124+ * Run a query scoped to your project as a readable object stream.
125+ *
126+ * @param {object= } query - Configuration object. See
127+ * {module:bigquery#query} for a complete list of options.
128+ * @return {stream }
129+ *
130+ * @example
131+ * var query = 'SELECT url FROM [publicdata:samples.github_nested] LIMIT 100';
132+ *
133+ * bigquery.createQueryStream(query)
134+ * .on('error', console.error)
135+ * .on('data', function(row) {
136+ * // row is a result from your query.
137+ * })
138+ * .on('end', function() {
139+ * // All rows retrieved.
140+ * });
141+ *
142+ * //-
143+ * // If you anticipate many results, you can end a stream early to prevent
144+ * // unnecessary processing and API requests.
145+ * //-
146+ * bigquery.createQueryStream(query)
147+ * .on('data', function(row) {
148+ * this.end();
149+ * });
150+ */
151+ BigQuery . prototype . createQueryStream = common . paginator . streamify ( 'query' ) ;
152+
123153/**
124154 * Create a reference to a dataset.
125155 *
@@ -146,7 +176,7 @@ BigQuery.prototype.dataset = function(id) {
146176 * @param {number } query.maxResults - Maximum number of results to return.
147177 * @param {string } query.pageToken - Token returned from a previous call, to
148178 * request the next page of results.
149- * @param {function= } callback - The callback function.
179+ * @param {function } callback - The callback function.
150180 * @param {?error } callback.err - An error returned while making this request
151181 * @param {module:bigquery/dataset[] } callback.datasets - The list of datasets
152182 * in your project.
@@ -173,27 +203,6 @@ BigQuery.prototype.dataset = function(id) {
173203 * bigquery.getDatasets({
174204 * autoPaginate: false
175205 * }, callback);
176- *
177- * //-
178- * // Get the datasets from your project as a readable object stream.
179- * //-
180- * bigquery.getDatasets()
181- * .on('error', console.error)
182- * .on('data', function(dataset) {
183- * // dataset is a Dataset object.
184- * })
185- * .on('end', function() {
186- * // All datasets retrieved.
187- * });
188- *
189- * //-
190- * // If you anticipate many results, you can end a stream early to prevent
191- * // unnecessary processing and API requests.
192- * //-
193- * bigquery.getDatasets()
194- * .on('data', function(dataset) {
195- * this.end();
196- * });
197206 */
198207BigQuery . prototype . getDatasets = function ( query , callback ) {
199208 var that = this ;
@@ -232,6 +241,36 @@ BigQuery.prototype.getDatasets = function(query, callback) {
232241 } ) ;
233242} ;
234243
244+ /**
245+ * List all or some of the {module:bigquery/dataset} objects in your project as
246+ * a readable object stream.
247+ *
248+ * @param {object= } query - Configuration object. See
249+ * {module:bigquery#getDatasets} for a complete list of options.
250+ * @return {stream }
251+ *
252+ * @example
253+ * bigquery.getDatasetsStream()
254+ * .on('error', console.error)
255+ * .on('data', function(dataset) {
256+ * // dataset is a Dataset object.
257+ * })
258+ * .on('end', function() {
259+ * // All datasets retrieved.
260+ * });
261+ *
262+ * //-
263+ * // If you anticipate many results, you can end a stream early to prevent
264+ * // unnecessary processing and API requests.
265+ * //-
266+ * bigquery.getDatasetsStream()
267+ * .on('data', function(dataset) {
268+ * this.end();
269+ * });
270+ */
271+ BigQuery . prototype . getDatasetsStream =
272+ common . paginator . streamify ( 'getDatasets' ) ;
273+
235274/**
236275 * Get all of the jobs from your project.
237276 *
@@ -251,7 +290,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
251290 * "minimal", to not include the job configuration.
252291 * @param {string= } options.stateFilter - Filter for job state. Acceptable
253292 * values are "done", "pending", and "running".
254- * @param {function= } callback - The callback function.
293+ * @param {function } callback - The callback function.
255294 * @param {?error } callback.err - An error returned while making this request
256295 * @param {module:bigquery/job[] } callback.jobs - The list of jobs in your
257296 * project.
@@ -278,27 +317,6 @@ BigQuery.prototype.getDatasets = function(query, callback) {
278317 * bigquery.getJobs({
279318 * autoPaginate: false
280319 * }, callback);
281- *
282- * //-
283- * // Get the jobs from your project as a readable object stream.
284- * //-
285- * bigquery.getJobs()
286- * .on('error', console.error)
287- * .on('data', function(job) {
288- * // job is a Job object.
289- * })
290- * .on('end', function() {
291- * // All jobs retrieved.
292- * });
293- *
294- * //-
295- * // If you anticipate many results, you can end a stream early to prevent
296- * // unnecessary processing and API requests.
297- * //-
298- * bigquery.getJobs()
299- * .on('data', function(job) {
300- * this.end();
301- * });
302320 */
303321BigQuery . prototype . getJobs = function ( options , callback ) {
304322 var that = this ;
@@ -337,6 +355,35 @@ BigQuery.prototype.getJobs = function(options, callback) {
337355 } ) ;
338356} ;
339357
358+ /**
359+ * List all or some of the {module:bigquery/job} objects in your project as a
360+ * readable object stream.
361+ *
362+ * @param {object= } query - Configuration object. See
363+ * {module:bigquery#getJobs} for a complete list of options.
364+ * @return {stream }
365+ *
366+ * @example
367+ * bigquery.getJobsStream()
368+ * .on('error', console.error)
369+ * .on('data', function(job) {
370+ * // job is a Job object.
371+ * })
372+ * .on('end', function() {
373+ * // All jobs retrieved.
374+ * });
375+ *
376+ * //-
377+ * // If you anticipate many results, you can end a stream early to prevent
378+ * // unnecessary processing and API requests.
379+ * //-
380+ * bigquery.getJobsStream()
381+ * .on('data', function(job) {
382+ * this.end();
383+ * });
384+ */
385+ BigQuery . prototype . getJobsStream = common . paginator . streamify ( 'getJobs' ) ;
386+
340387/**
341388 * Create a reference to an existing job.
342389 *
@@ -353,8 +400,6 @@ BigQuery.prototype.job = function(id) {
353400/**
354401 * Run a query scoped to your project.
355402 *
356- * This method also runs as a readable stream if you do not provide a callback.
357- *
358403 * @resource [Jobs: query API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/query}
359404 *
360405 * @param {string|object } options - A string SQL query or configuration object.
@@ -370,7 +415,7 @@ BigQuery.prototype.job = function(id) {
370415 * complete, in milliseconds, before returning. Default is to return
371416 * immediately. If the timeout passes before the job completes, the request
372417 * will fail with a `TIMEOUT` error.
373- * @param {function= } callback - The callback function.
418+ * @param {function } callback - The callback function.
374419 * @param {?error } callback.err - An error returned while making this request
375420 * @param {array } callback.rows - The list of results from your query.
376421 * @param {object } callback.apiResponse - The full API response.
@@ -398,28 +443,6 @@ BigQuery.prototype.job = function(id) {
398443 * query: query,
399444 * autoPaginate: false
400445 * }, callback);
401- *
402- * //-
403- * // You can also use the `query` method as a readable object stream by
404- * // omitting the callback.
405- * //-
406- * bigquery.query(query)
407- * .on('error', console.error)
408- * .on('data', function(row) {
409- * // row is a result from your query.
410- * })
411- * .on('end', function() {
412- * // All rows retrieved.
413- * });
414- *
415- * //-
416- * // If you anticipate many results, you can end a stream early to prevent
417- * // unnecessary processing and API requests.
418- * //-
419- * bigquery.query(query)
420- * .on('data', function(row) {
421- * this.end();
422- * });
423446 */
424447BigQuery . prototype . query = function ( options , callback ) {
425448 var self = this ;
@@ -590,10 +613,9 @@ BigQuery.prototype.startQuery = function(options, callback) {
590613
591614/*! Developer Documentation
592615 *
593- * These methods can be used with either a callback or as a readable object
594- * stream. `streamRouter` is used to add this dual behavior.
616+ * These methods can be auto-paginated.
595617 */
596- common . streamRouter . extend ( BigQuery , [ 'getDatasets' , 'getJobs' , 'query' ] ) ;
618+ common . paginator . extend ( BigQuery , [ 'getDatasets' , 'getJobs' , 'query' ] ) ;
597619
598620BigQuery . Dataset = Dataset ;
599621BigQuery . Job = Job ;
0 commit comments