本文整理汇总了TypeScript中@google-cloud/paginator.paginator.streamify方法的典型用法代码示例。如果您正苦于以下问题:TypeScript paginator.streamify方法的具体用法?TypeScript paginator.streamify怎么用?TypeScript paginator.streamify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@google-cloud/paginator.paginator
的用法示例。
在下文中一共展示了paginator.streamify方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: constructor
//.........这里部分代码省略.........
/**
* Sets the metadata of the Dataset object.
*
* @see [Datasets: patch API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/patch}
*
* @method Dataset#setMetadata
* @param {object} metadata Metadata to save on the Dataset.
* @param {function} [callback] The callback function.
* @param {?error} callback.err An error returned while making this
* request.
* @param {object} callback.apiResponse The full API response.
* @returns {Promise}
*
* @example
* const BigQuery = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
* const dataset = bigquery.dataset('institutions');
*
* const metadata = {
* description: 'Info for every institution in the 2013 IPEDS universe'
* };
*
* dataset.setMetadata(metadata, (err, apiResponse) => {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.setMetadata(metadata).then((data) => {
* const apiResponse = data[0];
* });
*/
setMetadata: true,
};
super({
parent: bigQuery,
baseUrl: '/datasets',
id: id,
methods: methods,
requestModule: request,
createMethod: (id, options, callback) => {
if (is.fn(options)) {
callback = options;
options = {};
}
options = extend({}, options, {location: this.location});
return bigQuery.createDataset(id, options, callback);
},
});
if (options && options.location) {
this.location = options.location;
}
this.bigQuery = bigQuery;
// Catch all for read-modify-write cycle
// https://cloud.google.com/bigquery/docs/api-performance#read-patch-write
this.interceptors.push({
request: function(reqOpts) {
if (reqOpts.method === 'PATCH' && reqOpts.json.etag) {
reqOpts.headers = reqOpts.headers || {};
reqOpts.headers['If-Match'] = reqOpts.json.etag;
}
return reqOpts;
},
});
/**
* List all or some of the {module:bigquery/table} objects in your project as a
* readable object stream.
*
* @param {object} [options] Configuration object. See
* {@link Dataset#getTables} for a complete list of options.
* @return {stream}
*
* @example
* const BigQuery = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
* const dataset = bigquery.dataset('institutions');
*
* dataset.getTablesStream()
* .on('error', console.error)
* .on('data', (table) => {})
* .on('end', () => {
* // All tables have been retrieved
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* dataset.getTablesStream()
* .on('data', function(table) {
* this.end();
* });
*/
this.getTablesStream = paginator.streamify('getTables');
}
示例2: constructor
//.........这里部分代码省略.........
* const BigQuery = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
*
* const job = bigquery.job('id');
* job.getMetadata((err, metadata, apiResponse) => {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.getMetadata().then((data) => {
* const metadata = data[0];
* const apiResponse = data[1];
* });
*/
getMetadata: {
reqOpts: {
qs: {location},
},
},
/**
* Set the metadata for this job. This can be useful for updating job
* labels.
*
* @see [Jobs: patch API Documentation]{@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/patch}
*
* @method Job#setMetadata
* @param {object} metadata Metadata to save on the Job.
* @param {function} [callback] The callback function.
* @param {?error} callback.err An error returned while making this
* request.
* @param {object} callback.apiResponse The full API response.
* @returns {Promise}
*
* @example
* const BigQuery = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
*
* const metadata = {
* configuration: {
* labels: {
* foo: 'bar'
* }
* }
* };
*
* const job = bigquery.job('job-id');
*
* job.setMetadata(metadata, (err, apiResponse) => {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.setMetadata(metadata).then((data) => {
* const apiResponse = data[0];
* });
*/
setMetadata: true,
};
super({
parent: bigQuery,
baseUrl: '/jobs',
id: id,
methods: methods,
requestModule: request,
} as any);
this.bigQuery = bigQuery;
if (options && options.location) {
this.location = options.location;
}
/**
* Get the results of a job as a readable object stream.
*
* @param {object} options Configuration object. See
* {@link Job#getQueryResults} for a complete list of options.
* @return {stream}
*
* @example
* const through2 = require('through2');
* const fs = require('fs');
* const BigQuery = require('@google-cloud/bigquery');
* const bigquery = new BigQuery();
*
* const job = bigquery.job('job-id');
*
* job.getQueryResultsStream()
* .pipe(through2.obj(function (row, enc, next) {
* this.push(JSON.stringify(row) + '\n');
* next();
* }))
* .pipe(fs.createWriteStream('./test/testdata/testfile.json'));
*/
this.getQueryResultsStream = paginator.streamify(
'getQueryResultsAsStream_'
);
}
示例3:
* })
* .on('end', function() {
* // All rows retrieved.
* });
*
* //-
* // If you anticipate many results, you can end a stream early to prevent
* // unnecessary processing and API requests.
* //-
* bigquery.createQueryStream(query)
* .on('data', function(row) {
* this.end();
* });
*/
BigQuery.prototype.createQueryStream = paginator.streamify(
'queryAsStream_'
);
/**
* Creates a job. Typically when creating a job you'll have a very specific task
* in mind. For this we recommend one of the following methods:
*
* - {@link BigQuery#createQueryJob}
* - {@link Table#createCopyJob}
* - {@link Table#createCopyFromJob}
* - {@link Table#createExtractJob}
* - {@link Table#createLoadJob}
*
* However in the event you need a finer level of control over the job creation,
* you can use this method to pass in a raw [Job resource](https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs)
* object.