Skip to content

Commit

Permalink
fix: update queryAsStream_ to set options with Query type (#999)
Browse files Browse the repository at this point in the history
* fix: update queryAsStream_ to set options with Query type

* add test and comment

Co-authored-by: meredithslota <meredithslota@google.com>
  • Loading branch information
steffnay and meredithslota committed Oct 12, 2021
1 parent 6250ad4 commit e7eab0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/bigquery.ts
Expand Up @@ -2012,7 +2012,9 @@ export class BigQuery extends common.Service {
cb?: SimpleQueryRowsCallback
) {
let options =
typeof optionsOrCallback === 'object' ? optionsOrCallback : {};
// Default to using query as options to ensure the options set
// in a Query type are passed through to the query() method.
typeof optionsOrCallback === 'object' ? optionsOrCallback : query;
const callback =
typeof optionsOrCallback === 'function' ? optionsOrCallback : cb;

Expand Down
14 changes: 13 additions & 1 deletion test/bigquery.ts
Expand Up @@ -2711,7 +2711,7 @@ describe('BigQuery', () => {
queryStub = sandbox.stub(bq, 'query').callsArgAsync(2);
});

it('should call query correctly', done => {
it('should call query correctly with a string', done => {
const query = 'SELECT';
bq.queryAsStream_(query, done);
assert(
Expand All @@ -2723,6 +2723,18 @@ describe('BigQuery', () => {
);
});

it('should call query correctly with a Query object', done => {
const query = {query: 'SELECT', wrapIntegers: true};
bq.queryAsStream_(query, done);
assert(
queryStub.calledOnceWithExactly(
query,
extend(query, {autoPaginate: false}),
sinon.match.func
)
);
});

it('should query as job if supplied', done => {
const cbStub = sinon.stub().callsArgAsync(1);
const query = {
Expand Down

0 comments on commit e7eab0b

Please sign in to comment.