Skip to content

Commit

Permalink
core: adding promise support (#1670)
Browse files Browse the repository at this point in the history
  • Loading branch information
callmehiphop authored and stephenplusplus committed Oct 14, 2016
1 parent ba75399 commit 7622a4e
Show file tree
Hide file tree
Showing 121 changed files with 4,822 additions and 200 deletions.
69 changes: 69 additions & 0 deletions packages/bigquery/src/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ function Dataset(bigQuery, id) {
* // The dataset was created successfully.
* }
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.create().then(function(data) {
* var dataset = data[0];
* var apiResponse = data[1];
* });
*/
create: true,

Expand All @@ -70,6 +78,13 @@ function Dataset(bigQuery, id) {
*
* @example
* dataset.exists(function(err, exists) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.exists().then(function(data) {
* var exists = data[0];
* });
*/
exists: true,

Expand All @@ -91,6 +106,14 @@ function Dataset(bigQuery, id) {
* // `dataset.metadata` has been populated.
* }
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.get().then(function(data) {
* var dataset = data[0];
* var apiResponse = data[1];
* });
*/
get: true,

Expand All @@ -107,6 +130,14 @@ function Dataset(bigQuery, id) {
*
* @example
* dataset.getMetadata(function(err, metadata, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.getMetadata().then(function(data) {
* var metadata = data[0];
* var apiResponse = data[1];
* });
*/
getMetadata: true,

Expand All @@ -127,6 +158,13 @@ function Dataset(bigQuery, id) {
* };
*
* dataset.setMetadata(metadata, function(err, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.setMetadata(metadata).then(function(data) {
* var apiResponse = data[0];
* });
*/
setMetadata: true
};
Expand Down Expand Up @@ -194,6 +232,14 @@ Dataset.prototype.createQueryStream = function(options) {
* };
*
* dataset.createTable(tableId, options, function(err, table, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.createTable(tableId, options).then(function(data) {
* var table = data[0];
* var apiResponse = data[1];
* });
*/
Dataset.prototype.createTable = function(id, options, callback) {
var self = this;
Expand Down Expand Up @@ -270,6 +316,13 @@ Dataset.prototype.createTable = function(id, options, callback) {
* // Delete the dataset and any tables it contains.
* //-
* dataset.delete({ force: true }, function(err, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.delete().then(function(data) {
* var apiResponse = data[0];
* });
*/
Dataset.prototype.delete = function(options, callback) {
if (!callback) {
Expand Down Expand Up @@ -310,6 +363,13 @@ Dataset.prototype.delete = function(options, callback) {
* dataset.getTables(function(err, tables, nextQuery, apiResponse) {
* // If `nextQuery` is non-null, there are more results to fetch.
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* dataset.getTables().then(function(data) {
* var tables = data[0];
* });
*/
Dataset.prototype.getTables = function(query, callback) {
var that = this;
Expand Down Expand Up @@ -414,4 +474,13 @@ Dataset.prototype.table = function(id) {
*/
common.paginator.extend(Dataset, ['getTables']);

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Dataset, {
exclude: ['table']
});

module.exports = Dataset;
46 changes: 46 additions & 0 deletions packages/bigquery/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ util.inherits(BigQuery, common.Service);
*
* @example
* bigquery.createDataset('my-dataset', function(err, dataset, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* bigquery.createDataset('my-dataset').then(function(data) {
* var dataset = data[0];
* var apiResponse = data[1];
* });
*/
BigQuery.prototype.createDataset = function(id, options, callback) {
var that = this;
Expand Down Expand Up @@ -203,6 +211,11 @@ BigQuery.prototype.dataset = function(id) {
* bigquery.getDatasets({
* autoPaginate: false
* }, callback);
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* bigquery.getDatasets().then(function(datasets) {});
*/
BigQuery.prototype.getDatasets = function(query, callback) {
var that = this;
Expand Down Expand Up @@ -317,6 +330,13 @@ BigQuery.prototype.getDatasetsStream =
* bigquery.getJobs({
* autoPaginate: false
* }, callback);
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* bigquery.getJobs().then(function(data) {
* var jobs = data[0];
* });
*/
BigQuery.prototype.getJobs = function(options, callback) {
var that = this;
Expand Down Expand Up @@ -443,6 +463,13 @@ BigQuery.prototype.job = function(id) {
* query: query,
* autoPaginate: false
* }, callback);
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* bigquery.query(query).then(function(data) {
* var rows = data[0];
* });
*/
BigQuery.prototype.query = function(options, callback) {
var self = this;
Expand Down Expand Up @@ -558,6 +585,16 @@ BigQuery.prototype.query = function(options, callback) {
* job.getQueryResults(function(err, rows, apiResponse) {});
* }
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* bigquery.startQuery(query).then(function(data) {
* var job = data[0];
* var apiResponse = data[1];
*
* return job.getQueryResults();
* });
*/
BigQuery.prototype.startQuery = function(options, callback) {
var that = this;
Expand Down Expand Up @@ -617,6 +654,15 @@ BigQuery.prototype.startQuery = function(options, callback) {
*/
common.paginator.extend(BigQuery, ['getDatasets', 'getJobs', 'query']);

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(BigQuery, {
exclude: ['dataset', 'job']
});

BigQuery.Dataset = Dataset;
BigQuery.Job = Job;
BigQuery.Table = Table;
Expand Down
44 changes: 44 additions & 0 deletions packages/bigquery/src/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,13 @@ function Job(bigQuery, id) {
*
* @example
* job.exists(function(err, exists) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.exists().then(function(data) {
* var exists = data[0];
* });
*/
exists: true,

Expand All @@ -99,6 +106,14 @@ function Job(bigQuery, id) {
* // `job.metadata` has been populated.
* }
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.get().then(function(data) {
* var job = data[0];
* var apiResponse = data[1];
* });
*/
get: true,

Expand All @@ -117,6 +132,14 @@ function Job(bigQuery, id) {
* @example
* var job = bigquery.job('id');
* job.getMetadata(function(err, metadata, apiResponse) {});
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.getMetadata().then(function(data) {
* var metadata = data[0];
* var apiResponse = data[1];
* });
*/
getMetadata: true
};
Expand Down Expand Up @@ -168,6 +191,13 @@ modelo.inherits(Job, common.ServiceObject, events.EventEmitter);
* job.on('error', function(err) {});
* job.on('complete', function(metadata) {});
* });
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.cancel().then(function(data) {
* var apiResponse = data[0];
* });
*/
Job.prototype.cancel = function(callback) {
callback = callback || common.util.noop;
Expand Down Expand Up @@ -238,6 +268,13 @@ Job.prototype.cancel = function(callback) {
* job.getQueryResults({
* autoPaginate: false
* }, callback);
*
* //-
* // If the callback is omitted, we'll return a Promise.
* //-
* job.getQueryResults().then(function(data) {
* var rows = data[0];
* });
*/
Job.prototype.getQueryResults = function(options, callback) {
if (is.fn(options)) {
Expand Down Expand Up @@ -341,4 +378,11 @@ Job.prototype.startPolling_ = function() {
});
};

/*! Developer Documentation
*
* All async methods (except for streams) will return a Promise in the event
* that a callback is omitted.
*/
common.util.promisifyAll(Job);

module.exports = Job;
Loading

0 comments on commit 7622a4e

Please sign in to comment.