Skip to content

Commit 233031b

Browse files
authored
chore(query): updates error message and docs for provided param types (#711)
* fix(docs): publish new version of docs with getTables documented * chore(query): updates error message and docs for provided param types * chore: removes only
1 parent 1851064 commit 233031b

2 files changed

Lines changed: 30 additions & 5 deletions

File tree

handwritten/bigquery/src/bigquery.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,9 @@ export class BigQuery extends common.Service {
809809
let typeName;
810810

811811
if (value === null) {
812-
throw new Error('Type must be provided for null values.');
812+
throw new Error(
813+
"Parameter types must be provided for null values via the 'types' field in query options."
814+
);
813815
}
814816

815817
if (value instanceof BigQueryDate) {
@@ -826,7 +828,9 @@ export class BigQuery extends common.Service {
826828
typeName = 'NUMERIC';
827829
} else if (Array.isArray(value)) {
828830
if (value.length === 0) {
829-
throw new Error('Type must be provided for empty array.');
831+
throw new Error(
832+
"Parameter types must be provided for empty arrays via the 'types' field in query options."
833+
);
830834
}
831835
return {
832836
type: 'ARRAY',
@@ -1624,6 +1628,10 @@ export class BigQuery extends common.Service {
16241628
* objects, Strings, Booleans, and Objects.
16251629
* @param {string} query.query A query string, following the BigQuery query
16261630
* syntax, of the query to execute.
1631+
* @param {object|Array<*>} query.types Provided types for query parameters.
1632+
* For positional SQL parameters, provide an array of types. For named
1633+
* SQL parameters, provide an object which maps each named parameter to
1634+
* its type.
16271635
* @param {boolean} [query.useLegacySql=false] Option to use legacy sql syntax.
16281636
* @param {object} [options] Configuration object for query results.
16291637
* @param {number} [options.maxResults] Maximum number of results to read.
@@ -1679,6 +1687,23 @@ export class BigQuery extends common.Service {
16791687
* }, function(err, rows) {});
16801688
*
16811689
* //-
1690+
* // Providing types for SQL parameters is supported.
1691+
* //-
1692+
* bigquery.query({
1693+
* query: [
1694+
* 'SELECT url',
1695+
* 'FROM `publicdata.samples.github_nested`',
1696+
* 'WHERE repository.owner = ?'
1697+
* ].join(' '),
1698+
*
1699+
* params: [
1700+
* null
1701+
* ],
1702+
*
1703+
* types: ['string']
1704+
* }, function(err, rows) {});
1705+
*
1706+
* //-
16821707
* // If you need to use a `DATE`, `DATETIME`, `TIME`, or `TIMESTAMP` type in
16831708
* // your query, see {@link BigQuery#date}, {@link BigQuery#datetime},
16841709
* // {@link BigQuery#time}, and {@link BigQuery#timestamp}.

handwritten/bigquery/test/bigquery.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,12 @@ describe('BigQuery', () => {
753753
it('should throw with an empty array', () => {
754754
assert.throws(() => {
755755
BigQuery.getTypeDescriptorFromValue_([]);
756-
}, /Type must be provided for empty array./);
756+
}, /Parameter types must be provided for empty arrays via the 'types' field in query options./);
757757
});
758758

759-
it('should throw with an null value', () => {
759+
it('should throw with a null value', () => {
760760
const expectedError = new RegExp(
761-
'Type must be provided for null values.'
761+
"Parameter types must be provided for null values via the 'types' field in query options."
762762
);
763763

764764
assert.throws(() => {

0 commit comments

Comments
 (0)