Skip to content

Commit

Permalink
Add apiResponse parameter to callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanseys committed Apr 16, 2015
1 parent 845416d commit b1af0d0
Show file tree
Hide file tree
Showing 26 changed files with 971 additions and 244 deletions.
28 changes: 14 additions & 14 deletions lib/bigquery/dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Dataset(bigQuery, id) {
* schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'
* };
*
* dataset.createTable(tableConfig, function(err, table) {});
* dataset.createTable(tableConfig, function(err, table, apiResponse) {});
*/
Dataset.prototype.createTable = function(options, callback) {
var that = this;
Expand All @@ -94,14 +94,14 @@ Dataset.prototype.createTable = function(options, callback) {

this.makeReq_('POST', '/tables', null, options, function(err, resp) {
if (err) {
callback(err);
callback(err, null, resp);
return;
}

var table = that.table(resp.tableReference.tableId);
table.metadata = resp;

callback(null, table);
callback(null, table, resp);
});
};

Expand All @@ -117,12 +117,12 @@ Dataset.prototype.createTable = function(options, callback) {
* //-
* // Delete the dataset, only if it does not have any tables.
* //-
* dataset.delete(function(err) {});
* dataset.delete(function(err, apiResponse) {});
*
* //-
* // Delete the dataset and any tables it contains.
* //-
* dataset.delete({ force: true }, function(err) {});
* dataset.delete({ force: true }, function(err, apiResponse) {});
*/
Dataset.prototype.delete = function(options, callback) {
if (!callback) {
Expand All @@ -143,19 +143,19 @@ Dataset.prototype.delete = function(options, callback) {
* @param {function} callback - The callback function.
*
* @example
* dataset.getMetadata(function(err, metadata) {});
* dataset.getMetadata(function(err, metadata, apiResponse) {});
*/
Dataset.prototype.getMetadata = function(callback) {
var that = this;
this.makeReq_('GET', '', null, null, function(err, resp) {
if (err) {
callback(err);
callback(err, null, resp);
return;
}

that.metadata = resp;

callback(null, that.metadata);
callback(null, that.metadata, resp);
});
};

Expand All @@ -169,7 +169,7 @@ Dataset.prototype.getMetadata = function(callback) {
* @param {function} callback - The callback function.
*
* @example
* dataset.getTables(function(err, tables, nextQuery) {
* dataset.getTables(function(err, tables, nextQuery, apiResponse) {
* // If `nextQuery` is non-null, there are more results to fetch.
* });
*/
Expand All @@ -185,7 +185,7 @@ Dataset.prototype.getTables = function(query, callback) {

this.makeReq_('GET', '/tables', query, null, function(err, resp) {
if (err) {
callback(err);
callback(err, null, null, resp);
return;
}

Expand All @@ -203,7 +203,7 @@ Dataset.prototype.getTables = function(query, callback) {
return table;
});

callback(null, tables, nextQuery);
callback(null, tables, nextQuery, resp);
});
};

Expand Down Expand Up @@ -239,20 +239,20 @@ Dataset.prototype.query = function(options, callback) {
* description: 'Information for every institution in the 2013 IPEDS universe'
* };
*
* dataset.setMetadata(metadata, function(err) {});
* dataset.setMetadata(metadata, function(err, apiResponse) {});
*/
Dataset.prototype.setMetadata = function(metadata, callback) {
var that = this;

this.makeReq_('PATCH', '', null, metadata, function(err, resp) {
if (err) {
callback(err);
callback(err, resp);
return;
}

that.metadata = resp;

callback(null, that.metadata);
callback(null, that.metadata, resp);
});
};

Expand Down
43 changes: 24 additions & 19 deletions lib/bigquery/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ var SCOPES = ['https://www.googleapis.com/auth/bigquery'];
* @alias module:bigquery
* @constructor
*
* @param {object=} options - Configuration object.
*
* @example
* var gcloud = require('gcloud');
*
Expand Down Expand Up @@ -125,7 +127,7 @@ function BigQuery(options) {
* @param {function} callback - The callback function.
*
* @example
* bigquery.createDataset('higher_education', function(err, dataset) {});
* bigquery.createDataset('my-dataset', function(err, dataset, apiResponse) {});
*/
BigQuery.prototype.createDataset = function(id, callback) {
var that = this;
Expand All @@ -138,14 +140,14 @@ BigQuery.prototype.createDataset = function(id, callback) {

this.makeReq_('POST', '/datasets', null, body, function(err, resp) {
if (err) {
callback(err);
callback(err, null, resp);
return;
}

var dataset = that.dataset(id);
dataset.metadata = resp;

callback(null, dataset);
callback(null, dataset, resp);
});
};

Expand Down Expand Up @@ -173,7 +175,7 @@ BigQuery.prototype.dataset = function(id) {
* @param {function} callback - The callback function.
*
* @example
* bigquery.getDatasets(function(err, datasets, nextQuery) {
* bigquery.getDatasets(function(err, datasets, nextQuery, apiResponse) {
* // If `nextQuery` is non-null, there are more results to fetch.
* });
*/
Expand All @@ -189,7 +191,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {

this.makeReq_('GET', '/datasets', query, null, function(err, resp) {
if (err) {
callback(err);
callback(err, null, null, resp);
return;
}

Expand All @@ -207,7 +209,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
return ds;
});

callback(null, datasets, nextQuery);
callback(null, datasets, nextQuery, resp);
});
};

Expand All @@ -228,7 +230,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
* @param {function} callback - The callback function.
*
* @example
* bigquery.getJobs(function(err, jobs, nextQuery) {
* bigquery.getJobs(function(err, jobs, nextQuery, apiResponse) {
* // If `nextQuery` is non-null, there are more results to fetch.
* });
*/
Expand All @@ -244,7 +246,7 @@ BigQuery.prototype.getJobs = function(options, callback) {

this.makeReq_('GET', '/jobs', options, null, function(err, resp) {
if (err) {
callback(err);
callback(err, null, null, resp);
return;
}

Expand All @@ -262,7 +264,7 @@ BigQuery.prototype.getJobs = function(options, callback) {
return job;
});

callback(null, jobs, nextQuery);
callback(null, jobs, nextQuery, resp);
});
};

Expand Down Expand Up @@ -336,9 +338,12 @@ BigQuery.prototype.job = function(id) {
* //-
* // You can run a query against your data in a serial manner.
* //-
* bigquery.query(query, function(err, rows, nextQuery) {
* bigquery.query(query, function(err, rows, nextQuery, apiResponse) {
* // Handle results here.
* if (nextQuery) {
* bigquery.query(nextQuery, function(err, rows, nextQuery) {});
* bigquery.query(nextQuery, function(err, rows, nextQuery, apiResponse) {
* // Handle more results here.
* });
* }
* });
*
Expand Down Expand Up @@ -387,7 +392,7 @@ BigQuery.prototype.query = function(options, callback) {

function responseHandler(err, resp) {
if (err) {
onComplete(err);
onComplete(err, null, null, resp);
return;
}

Expand All @@ -409,16 +414,16 @@ BigQuery.prototype.query = function(options, callback) {
});
}

onComplete(null, rows, nextQuery);
onComplete(null, rows, nextQuery, resp);
}

function onComplete(err, rows, nextQuery) {
function onComplete(err, rows, nextQuery, resp) {
if (err) {
if (stream) {
stream.emit('error', err);
stream.end();
} else {
callback(err);
callback(err, null, null, resp);
}
return;
}
Expand All @@ -434,7 +439,7 @@ BigQuery.prototype.query = function(options, callback) {
stream.end();
}
} else {
callback(null, rows, nextQuery);
callback(null, rows, nextQuery, resp);
}
}
}
Expand Down Expand Up @@ -484,7 +489,7 @@ BigQuery.prototype.query = function(options, callback) {
* //-
* bigquery.startQuery(query, function(err, job) {
* if (!err) {
* job.getQueryResults(function(err, rows) {});
* job.getQueryResults(function(err, rows, apiResponse) {});
* }
* });
*/
Expand Down Expand Up @@ -525,14 +530,14 @@ BigQuery.prototype.startQuery = function(options, callback) {

this.makeReq_('POST', '/jobs', null, body, function(err, resp) {
if (err) {
callback(err);
callback(err, null, resp);
return;
}

var job = that.job(resp.jobReference.jobId);
job.metadata = resp;

callback(null, job);
callback(null, job, resp);
});
};

Expand Down
10 changes: 5 additions & 5 deletions lib/bigquery/job.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function Job(bigQuery, id) {
* @param {function} callback - The callback function.
*
* @example
* job.getMetadata(function(err, metadata) {});
* job.getMetadata(function(err, metadata, apiResponse) {});
*/
Job.prototype.getMetadata = function(callback) {
var that = this;
Expand All @@ -71,13 +71,13 @@ Job.prototype.getMetadata = function(callback) {

this.bigQuery.makeReq_('GET', path, null, null, function(err, resp) {
if (err) {
callback(err);
callback(err, null, resp);
return;
}

that.metadata = resp;

callback(null, that.metadata);
callback(null, that.metadata, resp);
});
};

Expand All @@ -102,7 +102,7 @@ Job.prototype.getMetadata = function(callback) {
* //-
* // Use the default options to get the results of a query.
* //-
* job.getQueryResults(function(err, rows, nextQuery) {});
* job.getQueryResults(function(err, rows, nextQuery, apiResponse) {});
*
* //-
* // Customize the results you want to fetch.
Expand All @@ -111,7 +111,7 @@ Job.prototype.getMetadata = function(callback) {
* maxResults: 100
* };
*
* job.getQueryResults(options, function(err, rows, nextQuery) {});
* job.getQueryResults(options, function(err, rows, nextQuery, apiResponse) {});
*
* //-
* // Consume the results from the query as a readable stream.
Expand Down
Loading

0 comments on commit b1af0d0

Please sign in to comment.