Skip to content

Commit b191a22

Browse files
Merge pull request #448 from ryanseys/add-apiResponses
Add apiResponses
2 parents 845416d + b1af0d0 commit b191a22

File tree

26 files changed

+971
-244
lines changed

26 files changed

+971
-244
lines changed

lib/bigquery/dataset.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function Dataset(bigQuery, id) {
7373
* schema: 'UNITID,INSTNM,ADDR,CITY,STABBR,ZIP,FIPS,OBEREG,CHFNM,...'
7474
* };
7575
*
76-
* dataset.createTable(tableConfig, function(err, table) {});
76+
* dataset.createTable(tableConfig, function(err, table, apiResponse) {});
7777
*/
7878
Dataset.prototype.createTable = function(options, callback) {
7979
var that = this;
@@ -94,14 +94,14 @@ Dataset.prototype.createTable = function(options, callback) {
9494

9595
this.makeReq_('POST', '/tables', null, options, function(err, resp) {
9696
if (err) {
97-
callback(err);
97+
callback(err, null, resp);
9898
return;
9999
}
100100

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

104-
callback(null, table);
104+
callback(null, table, resp);
105105
});
106106
};
107107

@@ -117,12 +117,12 @@ Dataset.prototype.createTable = function(options, callback) {
117117
* //-
118118
* // Delete the dataset, only if it does not have any tables.
119119
* //-
120-
* dataset.delete(function(err) {});
120+
* dataset.delete(function(err, apiResponse) {});
121121
*
122122
* //-
123123
* // Delete the dataset and any tables it contains.
124124
* //-
125-
* dataset.delete({ force: true }, function(err) {});
125+
* dataset.delete({ force: true }, function(err, apiResponse) {});
126126
*/
127127
Dataset.prototype.delete = function(options, callback) {
128128
if (!callback) {
@@ -143,19 +143,19 @@ Dataset.prototype.delete = function(options, callback) {
143143
* @param {function} callback - The callback function.
144144
*
145145
* @example
146-
* dataset.getMetadata(function(err, metadata) {});
146+
* dataset.getMetadata(function(err, metadata, apiResponse) {});
147147
*/
148148
Dataset.prototype.getMetadata = function(callback) {
149149
var that = this;
150150
this.makeReq_('GET', '', null, null, function(err, resp) {
151151
if (err) {
152-
callback(err);
152+
callback(err, null, resp);
153153
return;
154154
}
155155

156156
that.metadata = resp;
157157

158-
callback(null, that.metadata);
158+
callback(null, that.metadata, resp);
159159
});
160160
};
161161

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

186186
this.makeReq_('GET', '/tables', query, null, function(err, resp) {
187187
if (err) {
188-
callback(err);
188+
callback(err, null, null, resp);
189189
return;
190190
}
191191

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

206-
callback(null, tables, nextQuery);
206+
callback(null, tables, nextQuery, resp);
207207
});
208208
};
209209

@@ -239,20 +239,20 @@ Dataset.prototype.query = function(options, callback) {
239239
* description: 'Information for every institution in the 2013 IPEDS universe'
240240
* };
241241
*
242-
* dataset.setMetadata(metadata, function(err) {});
242+
* dataset.setMetadata(metadata, function(err, apiResponse) {});
243243
*/
244244
Dataset.prototype.setMetadata = function(metadata, callback) {
245245
var that = this;
246246

247247
this.makeReq_('PATCH', '', null, metadata, function(err, resp) {
248248
if (err) {
249-
callback(err);
249+
callback(err, resp);
250250
return;
251251
}
252252

253253
that.metadata = resp;
254254

255-
callback(null, that.metadata);
255+
callback(null, that.metadata, resp);
256256
});
257257
};
258258

lib/bigquery/index.js

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ var SCOPES = ['https://www.googleapis.com/auth/bigquery'];
7272
* @alias module:bigquery
7373
* @constructor
7474
*
75+
* @param {object=} options - Configuration object.
76+
*
7577
* @example
7678
* var gcloud = require('gcloud');
7779
*
@@ -125,7 +127,7 @@ function BigQuery(options) {
125127
* @param {function} callback - The callback function.
126128
*
127129
* @example
128-
* bigquery.createDataset('higher_education', function(err, dataset) {});
130+
* bigquery.createDataset('my-dataset', function(err, dataset, apiResponse) {});
129131
*/
130132
BigQuery.prototype.createDataset = function(id, callback) {
131133
var that = this;
@@ -138,14 +140,14 @@ BigQuery.prototype.createDataset = function(id, callback) {
138140

139141
this.makeReq_('POST', '/datasets', null, body, function(err, resp) {
140142
if (err) {
141-
callback(err);
143+
callback(err, null, resp);
142144
return;
143145
}
144146

145147
var dataset = that.dataset(id);
146148
dataset.metadata = resp;
147149

148-
callback(null, dataset);
150+
callback(null, dataset, resp);
149151
});
150152
};
151153

@@ -173,7 +175,7 @@ BigQuery.prototype.dataset = function(id) {
173175
* @param {function} callback - The callback function.
174176
*
175177
* @example
176-
* bigquery.getDatasets(function(err, datasets, nextQuery) {
178+
* bigquery.getDatasets(function(err, datasets, nextQuery, apiResponse) {
177179
* // If `nextQuery` is non-null, there are more results to fetch.
178180
* });
179181
*/
@@ -189,7 +191,7 @@ BigQuery.prototype.getDatasets = function(query, callback) {
189191

190192
this.makeReq_('GET', '/datasets', query, null, function(err, resp) {
191193
if (err) {
192-
callback(err);
194+
callback(err, null, null, resp);
193195
return;
194196
}
195197

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

210-
callback(null, datasets, nextQuery);
212+
callback(null, datasets, nextQuery, resp);
211213
});
212214
};
213215

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

245247
this.makeReq_('GET', '/jobs', options, null, function(err, resp) {
246248
if (err) {
247-
callback(err);
249+
callback(err, null, null, resp);
248250
return;
249251
}
250252

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

265-
callback(null, jobs, nextQuery);
267+
callback(null, jobs, nextQuery, resp);
266268
});
267269
};
268270

@@ -336,9 +338,12 @@ BigQuery.prototype.job = function(id) {
336338
* //-
337339
* // You can run a query against your data in a serial manner.
338340
* //-
339-
* bigquery.query(query, function(err, rows, nextQuery) {
341+
* bigquery.query(query, function(err, rows, nextQuery, apiResponse) {
342+
* // Handle results here.
340343
* if (nextQuery) {
341-
* bigquery.query(nextQuery, function(err, rows, nextQuery) {});
344+
* bigquery.query(nextQuery, function(err, rows, nextQuery, apiResponse) {
345+
* // Handle more results here.
346+
* });
342347
* }
343348
* });
344349
*
@@ -387,7 +392,7 @@ BigQuery.prototype.query = function(options, callback) {
387392

388393
function responseHandler(err, resp) {
389394
if (err) {
390-
onComplete(err);
395+
onComplete(err, null, null, resp);
391396
return;
392397
}
393398

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

412-
onComplete(null, rows, nextQuery);
417+
onComplete(null, rows, nextQuery, resp);
413418
}
414419

415-
function onComplete(err, rows, nextQuery) {
420+
function onComplete(err, rows, nextQuery, resp) {
416421
if (err) {
417422
if (stream) {
418423
stream.emit('error', err);
419424
stream.end();
420425
} else {
421-
callback(err);
426+
callback(err, null, null, resp);
422427
}
423428
return;
424429
}
@@ -434,7 +439,7 @@ BigQuery.prototype.query = function(options, callback) {
434439
stream.end();
435440
}
436441
} else {
437-
callback(null, rows, nextQuery);
442+
callback(null, rows, nextQuery, resp);
438443
}
439444
}
440445
}
@@ -484,7 +489,7 @@ BigQuery.prototype.query = function(options, callback) {
484489
* //-
485490
* bigquery.startQuery(query, function(err, job) {
486491
* if (!err) {
487-
* job.getQueryResults(function(err, rows) {});
492+
* job.getQueryResults(function(err, rows, apiResponse) {});
488493
* }
489494
* });
490495
*/
@@ -525,14 +530,14 @@ BigQuery.prototype.startQuery = function(options, callback) {
525530

526531
this.makeReq_('POST', '/jobs', null, body, function(err, resp) {
527532
if (err) {
528-
callback(err);
533+
callback(err, null, resp);
529534
return;
530535
}
531536

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

535-
callback(null, job);
540+
callback(null, job, resp);
536541
});
537542
};
538543

lib/bigquery/job.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ function Job(bigQuery, id) {
6262
* @param {function} callback - The callback function.
6363
*
6464
* @example
65-
* job.getMetadata(function(err, metadata) {});
65+
* job.getMetadata(function(err, metadata, apiResponse) {});
6666
*/
6767
Job.prototype.getMetadata = function(callback) {
6868
var that = this;
@@ -71,13 +71,13 @@ Job.prototype.getMetadata = function(callback) {
7171

7272
this.bigQuery.makeReq_('GET', path, null, null, function(err, resp) {
7373
if (err) {
74-
callback(err);
74+
callback(err, null, resp);
7575
return;
7676
}
7777

7878
that.metadata = resp;
7979

80-
callback(null, that.metadata);
80+
callback(null, that.metadata, resp);
8181
});
8282
};
8383

@@ -102,7 +102,7 @@ Job.prototype.getMetadata = function(callback) {
102102
* //-
103103
* // Use the default options to get the results of a query.
104104
* //-
105-
* job.getQueryResults(function(err, rows, nextQuery) {});
105+
* job.getQueryResults(function(err, rows, nextQuery, apiResponse) {});
106106
*
107107
* //-
108108
* // Customize the results you want to fetch.
@@ -111,7 +111,7 @@ Job.prototype.getMetadata = function(callback) {
111111
* maxResults: 100
112112
* };
113113
*
114-
* job.getQueryResults(options, function(err, rows, nextQuery) {});
114+
* job.getQueryResults(options, function(err, rows, nextQuery, apiResponse) {});
115115
*
116116
* //-
117117
* // Consume the results from the query as a readable stream.

0 commit comments

Comments
 (0)