[go: up one dir, main page]

Skip to content

Commit

Permalink
feat: support JSON query param (#1329)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarowolfx committed Jan 24, 2024
1 parent 9e85219 commit e9f133b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/bigquery.ts
Expand Up @@ -1005,6 +1005,8 @@ export class BigQuery extends Service {
'GEOGRAPHY',
'ARRAY',
'STRUCT',
'JSON',
'RANGE',
];

if (is.array(providedType)) {
Expand Down Expand Up @@ -1182,6 +1184,8 @@ export class BigQuery extends Service {
},
{}
);
} else if (typeName === 'JSON' && is.object(value)) {
queryParameter.parameterValue!.value = JSON.stringify(value);
} else {
queryParameter.parameterValue!.value = BigQuery._getValue(
value,
Expand Down
27 changes: 27 additions & 0 deletions test/bigquery.ts
Expand Up @@ -1521,6 +1521,33 @@ describe('BigQuery', () => {
assert.deepStrictEqual(param, expectedParam);
});

it('should format JSON types', () => {
const typeName = 'JSON';
const value = {
foo: 'bar',
};
const strValue = JSON.stringify(value);
assert.deepStrictEqual(BigQuery.valueToQueryParameter_(value, typeName), {
parameterType: {
type: typeName,
},
parameterValue: {
value: strValue,
},
});
assert.deepStrictEqual(
BigQuery.valueToQueryParameter_(strValue, typeName),
{
parameterType: {
type: typeName,
},
parameterValue: {
value: strValue,
},
}
);
});

it('should format all other types', () => {
const typeName = 'ANY-TYPE';
sandbox.stub(BigQuery, 'getTypeDescriptorFromValue_').returns({
Expand Down

0 comments on commit e9f133b

Please sign in to comment.