Skip to content

Commit 29194d3

Browse files
bigquery#query: stop passing Job object to API
1 parent 01ec51f commit 29194d3

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

lib/bigquery/index.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,11 @@ BigQuery.prototype.query = function(options, callback) {
361361

362362
options = options || {};
363363

364+
var requestQuery = {
365+
maxResults: options.maxResults,
366+
timeoutMs: options.timeoutMs,
367+
};
368+
364369
if (!util.is(callback, 'function')) {
365370
stream = streamEvents(through.obj());
366371
stream.once('reading', runQuery);
@@ -372,8 +377,9 @@ BigQuery.prototype.query = function(options, callback) {
372377

373378
function runQuery() {
374379
if (options.job) {
375-
that.makeReq_(
376-
'GET', '/queries/' + options.job.id, options, null, responseHandler);
380+
// Get results of the query.
381+
var path = '/queries/' + options.job.id;
382+
that.makeReq_('GET', path, requestQuery, null, responseHandler);
377383
} else {
378384
// Create a job.
379385
that.makeReq_('POST', '/queries', null, options, responseHandler);

test/bigquery/index.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -366,23 +366,33 @@ describe('BigQuery', function() {
366366
};
367367

368368
bq.makeReq_ = function(method, path, query, body) {
369-
assert.equal(body.query, QUERY_STRING);
370-
assert.equal(body.a, 'b');
371-
assert.equal(body.c, 'd');
369+
assert.deepEqual(body, options);
372370
done();
373371
};
374372

375373
bq.query(options, assert.ifError);
376374
});
377375

378376
it('should get the results of a job if one is provided', function(done) {
379-
bq.makeReq_ = function(method, path) {
377+
var options = {
378+
job: bq.job(JOB_ID),
379+
maxResults: 10,
380+
timeoutMs: 8,
381+
};
382+
383+
var expectedRequestQuery = {
384+
maxResults: 10,
385+
timeoutMs: 8
386+
};
387+
388+
bq.makeReq_ = function(method, path, query) {
380389
assert.equal(method, 'GET');
381390
assert.equal(path, '/queries/' + JOB_ID);
391+
assert.deepEqual(query, expectedRequestQuery);
382392
done();
383393
};
384394

385-
bq.query({ job: bq.job(JOB_ID) }, assert.ifError);
395+
bq.query(options, assert.ifError);
386396
});
387397

388398
it('should be a stream if a callback is omitted', function() {

0 commit comments

Comments
 (0)