UNPKG

42.8 kBTypeScriptView Raw
1/*!
2 * Copyright 2019 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import { Service, GoogleAuthOptions } from '@google-cloud/common';
17import { ResourceStream } from '@google-cloud/paginator';
18import { Dataset, DatasetOptions } from './dataset';
19import { Job, JobOptions, QueryResultsOptions } from './job';
20import { Table, TableField, TableSchema, TableRow, JobCallback, JobResponse, RowMetadata } from './table';
21import bigquery from './types';
22export interface RequestCallback<T> {
23 (err: Error | null, response?: T | null): void;
24}
25export interface ResourceCallback<T, R> {
26 (err: Error | null, resource?: T | null, response?: R | null): void;
27}
28export type PagedResponse<T, Q, R> = [T[]] | [T[], Q | null, R];
29export interface PagedCallback<T, Q, R> {
30 (err: Error | null, resource?: T[] | null, nextQuery?: Q | null, response?: R | null): void;
31}
32export type JobRequest<J> = J & {
33 jobId?: string;
34 jobPrefix?: string;
35 location?: string;
36 projectId?: string;
37};
38export type PagedRequest<P> = P & {
39 autoPaginate?: boolean;
40 maxApiCalls?: number;
41};
42export type QueryRowsResponse = PagedResponse<RowMetadata, Query, bigquery.IGetQueryResultsResponse>;
43export type QueryRowsCallback = PagedCallback<RowMetadata, Query, bigquery.IGetQueryResultsResponse>;
44export type SimpleQueryRowsResponse = [RowMetadata[], bigquery.IJob];
45export type SimpleQueryRowsCallback = ResourceCallback<RowMetadata[], bigquery.IJob>;
46export type Query = JobRequest<bigquery.IJobConfigurationQuery> & {
47 destination?: Table;
48 params?: any[] | {
49 [param: string]: any;
50 };
51 dryRun?: boolean;
52 labels?: {
53 [label: string]: string;
54 };
55 types?: string[] | string[][] | {
56 [type: string]: string | string[];
57 };
58 job?: Job;
59 maxResults?: number;
60 jobTimeoutMs?: number;
61 pageToken?: string;
62 wrapIntegers?: boolean | IntegerTypeCastOptions;
63};
64export type QueryOptions = QueryResultsOptions;
65export type QueryStreamOptions = {
66 wrapIntegers?: boolean | IntegerTypeCastOptions;
67};
68export type DatasetResource = bigquery.IDataset;
69export type ValueType = bigquery.IQueryParameterType;
70export type GetDatasetsOptions = PagedRequest<bigquery.datasets.IListParams>;
71export type DatasetsResponse = PagedResponse<Dataset, GetDatasetsOptions, bigquery.IDatasetList>;
72export type DatasetsCallback = PagedCallback<Dataset, GetDatasetsOptions, bigquery.IDatasetList>;
73export type DatasetResponse = [Dataset, bigquery.IDataset];
74export type DatasetCallback = ResourceCallback<Dataset, bigquery.IDataset>;
75export type GetJobsOptions = PagedRequest<bigquery.jobs.IListParams>;
76export type GetJobsResponse = PagedResponse<Job, GetJobsOptions, bigquery.IJobList>;
77export type GetJobsCallback = PagedCallback<Job, GetJobsOptions, bigquery.IJobList>;
78export interface BigQueryTimeOptions {
79 hours?: number | string;
80 minutes?: number | string;
81 seconds?: number | string;
82 fractional?: number | string;
83}
84export interface BigQueryDateOptions {
85 year?: number | string;
86 month?: number | string;
87 day?: number | string;
88}
89export interface BigQueryDatetimeOptions {
90 year?: string | number;
91 month?: string | number;
92 day?: string | number;
93 hours?: string | number;
94 minutes?: string | number;
95 seconds?: string | number;
96 fractional?: string | number;
97}
98export type ProvidedTypeArray = Array<ProvidedTypeStruct | string | []>;
99export interface ProvidedTypeStruct {
100 [key: string]: string | ProvidedTypeArray | ProvidedTypeStruct;
101}
102export type QueryParameter = bigquery.IQueryParameter;
103export interface BigQueryOptions extends GoogleAuthOptions {
104 /**
105 * Automatically retry requests if the
106 * response is related to rate limits or certain intermittent server errors.
107 * We will exponentially backoff subsequent requests by default.
108 *
109 * Defaults to `true`.
110 */
111 autoRetry?: boolean;
112 /**
113 * Maximum number of automatic retries
114 * attempted before returning the error.
115 *
116 * Defaults to 3.
117 */
118 maxRetries?: number;
119 /**
120 * The geographic location of all datasets and
121 * jobs referenced and created through the client.
122 */
123 location?: string;
124 /**
125 * The value to be prepended to the User-Agent
126 * header in API requests.
127 */
128 userAgent?: string;
129 /**
130 * The API endpoint of the service used to make requests.
131 * Defaults to `bigquery.googleapis.com`.
132 */
133 apiEndpoint?: string;
134}
135export interface IntegerTypeCastOptions {
136 integerTypeCastFunction: Function;
137 fields?: string | string[];
138}
139export type IntegerTypeCastValue = {
140 integerValue: string | number;
141 schemaFieldName?: string;
142};
143export declare const PROTOCOL_REGEX: RegExp;
144/**
145 * @typedef {object} BigQueryOptions
146 * @property {string} [projectId] The project ID from the Google Developer's
147 * Console, e.g. 'grape-spaceship-123'. We will also check the environment
148 * variable `GCLOUD_PROJECT` for your project ID. If your app is running in
149 * an environment which supports {@link
150 * https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application
151 * Application Default Credentials}, your project ID will be detected
152 * automatically.
153 * @property {string} [keyFilename] Full path to the a .json, .pem, or .p12 key
154 * downloaded from the Google Developers Console. If you provide a path to a
155 * JSON file, the `projectId` option above is not necessary. NOTE: .pem and
156 * .p12 require you to specify the `email` option as well.
157 * @property {string} [token] An OAUTH access token. If provided, we will not
158 * manage fetching, re-using, and re-minting access tokens.
159 * @property {string} [email] Account email address. Required when using a .pem
160 * or .p12 keyFilename.
161 * @property {object} [credentials] Credentials object.
162 * @property {string} [credentials.client_email]
163 * @property {string} [credentials.private_key]
164 * @property {Constructor} [promise] Custom promise module to use instead of
165 * native Promises.
166 * @property {string[]} [scopes] Additional OAuth scopes to use in requests. For
167 * example, to access an external data source, you may need the
168 * `https://www.googleapis.com/auth/drive.readonly` scope.
169 */
170/**
171 * In the following examples from this page and the other modules (`Dataset`,
172 * `Table`, etc.), we are going to be using a dataset from
173 * {@link http://goo.gl/f2SXcb| data.gov} of higher education institutions.
174 *
175 * We will create a table with the correct schema, import the public CSV file
176 * into that table, and query it for data.
177 *
178 * @class
179 *
180 * See {@link https://cloud.google.com/bigquery/what-is-bigquery| What is BigQuery?}
181 *
182 * @param {BigQueryOptions} options Constructor options.
183 *
184 * @example Install the client library with <a href="https://www.npmjs.com/">npm</a>:
185 * ```
186 * npm install @google-cloud/bigquery
187 *
188 * ```
189 * @example Import the client library
190 * ```
191 * const {BigQuery} = require('@google-cloud/bigquery');
192 *
193 * ```
194 * @example Create a client that uses <a href="https://cloud.google.com/docs/authentication/production#providing_credentials_to_your_application">Application Default Credentials (ADC)</a>:
195 * ```
196 * const bigquery = new BigQuery();
197 *
198 * ```
199 * @example Create a client with <a href="https://cloud.google.com/docs/authentication/production#obtaining_and_providing_service_account_credentials_manually">explicit credentials</a>:
200 * ```
201 * const bigquery = new BigQuery({
202 * projectId: 'your-project-id',
203 * keyFilename: '/path/to/keyfile.json'
204 * });
205 *
206 * ```
207 * @example <caption>include:samples/quickstart.js</caption>
208 * region_tag:bigquery_quickstart
209 * Full quickstart example:
210 */
211export declare class BigQuery extends Service {
212 location?: string;
213 createQueryStream(options?: Query | string): ResourceStream<RowMetadata>;
214 getDatasetsStream(options?: GetDatasetsOptions): ResourceStream<Dataset>;
215 getJobsStream(options?: GetJobsOptions): ResourceStream<Job>;
216 constructor(options?: BigQueryOptions);
217 private static sanitizeEndpoint;
218 /**
219 * Merge a rowset returned from the API with a table schema.
220 *
221 * @private
222 *
223 * @param {object} schema
224 * @param {array} rows
225 * @param {boolean|IntegerTypeCastOptions} wrapIntegers Wrap values of
226 * 'INT64' type in {@link BigQueryInt} objects.
227 * If a `boolean`, this will wrap values in {@link BigQueryInt} objects.
228 * If an `object`, this will return a value returned by
229 * `wrapIntegers.integerTypeCastFunction`.
230 * Please see {@link IntegerTypeCastOptions} for options descriptions.
231 * @param {array} selectedFields List of fields to return.
232 * If unspecified, all fields are returned.
233 * @returns Fields using their matching names from the table's schema.
234 */
235 static mergeSchemaWithRows_(schema: TableSchema | TableField, rows: TableRow[], wrapIntegers: boolean | IntegerTypeCastOptions, selectedFields?: string[]): any[];
236 /**
237 * The `DATE` type represents a logical calendar date, independent of time
238 * zone. It does not represent a specific 24-hour time period. Rather, a given
239 * DATE value represents a different 24-hour period when interpreted in
240 * different time zones, and may represent a shorter or longer day during
241 * Daylight Savings Time transitions.
242 *
243 * @param {object|string} value The date. If a string, this should be in the
244 * format the API describes: `YYYY-[M]M-[D]D`.
245 * Otherwise, provide an object.
246 * @param {string|number} value.year Four digits.
247 * @param {string|number} value.month One or two digits.
248 * @param {string|number} value.day One or two digits.
249 *
250 * @example
251 * ```
252 * const {BigQuery} = require('@google-cloud/bigquery');
253 * const bigquery = new BigQuery();
254 * const date = bigquery.date('2017-01-01');
255 *
256 * //-
257 * // Alternatively, provide an object.
258 * //-
259 * const date2 = bigquery.date({
260 * year: 2017,
261 * month: 1,
262 * day: 1
263 * });
264 * ```
265 */
266 static date(value: BigQueryDateOptions | string): BigQueryDate;
267 /**
268 * @param {object|string} value The date. If a string, this should be in the
269 * format the API describes: `YYYY-[M]M-[D]D`.
270 * Otherwise, provide an object.
271 * @param {string|number} value.year Four digits.
272 * @param {string|number} value.month One or two digits.
273 * @param {string|number} value.day One or two digits.
274 *
275 * @example
276 * ```
277 * const {BigQuery} = require('@google-cloud/bigquery');
278 * const date = BigQuery.date('2017-01-01');
279 *
280 * //-
281 * // Alternatively, provide an object.
282 * //-
283 * const date2 = BigQuery.date({
284 * year: 2017,
285 * month: 1,
286 * day: 1
287 * });
288 * ```
289 */
290 date(value: BigQueryDateOptions | string): BigQueryDate;
291 /**
292 * A `DATETIME` data type represents a point in time. Unlike a `TIMESTAMP`,
293 * this does not refer to an absolute instance in time. Instead, it is the
294 * civil time, or the time that a user would see on a watch or calendar.
295 *
296 * @method BigQuery.datetime
297 * @param {object|string} value The time. If a string, this should be in the
298 * format the API describes: `YYYY-[M]M-[D]D[ [H]H:[M]M:[S]S[.DDDDDD]]`.
299 * Otherwise, provide an object.
300 * @param {string|number} value.year Four digits.
301 * @param {string|number} value.month One or two digits.
302 * @param {string|number} value.day One or two digits.
303 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
304 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
305 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
306 * @param {string|number} [value.fractional] Up to six digits for microsecond
307 * precision.
308 *
309 * @example
310 * ```
311 * const {BigQuery} = require('@google-cloud/bigquery');
312 * const datetime = BigQuery.datetime('2017-01-01 13:00:00');
313 *
314 * //-
315 * // Alternatively, provide an object.
316 * //-
317 * const datetime = BigQuery.datetime({
318 * year: 2017,
319 * month: 1,
320 * day: 1,
321 * hours: 14,
322 * minutes: 0,
323 * seconds: 0
324 * });
325 * ```
326 */
327 /**
328 * A `DATETIME` data type represents a point in time. Unlike a `TIMESTAMP`,
329 * this does not refer to an absolute instance in time. Instead, it is the
330 * civil time, or the time that a user would see on a watch or calendar.
331 *
332 * @param {object|string} value The time. If a string, this should be in the
333 * format the API describes: `YYYY-[M]M-[D]D[ [H]H:[M]M:[S]S[.DDDDDD]]`.
334 * Otherwise, provide an object.
335 * @param {string|number} value.year Four digits.
336 * @param {string|number} value.month One or two digits.
337 * @param {string|number} value.day One or two digits.
338 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
339 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
340 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
341 * @param {string|number} [value.fractional] Up to six digits for microsecond
342 * precision.
343 *
344 * @example
345 * ```
346 * const {BigQuery} = require('@google-cloud/bigquery');
347 * const bigquery = new BigQuery();
348 * const datetime = bigquery.datetime('2017-01-01 13:00:00');
349 *
350 * //-
351 * // Alternatively, provide an object.
352 * //-
353 * const datetime = bigquery.datetime({
354 * year: 2017,
355 * month: 1,
356 * day: 1,
357 * hours: 14,
358 * minutes: 0,
359 * seconds: 0
360 * });
361 * ```
362 */
363 static datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
364 datetime(value: BigQueryDatetimeOptions | string): BigQueryDatetime;
365 /**
366 * A `TIME` data type represents a time, independent of a specific date.
367 *
368 * @method BigQuery.time
369 * @param {object|string} value The time. If a string, this should be in the
370 * format the API describes: `[H]H:[M]M:[S]S[.DDDDDD]`. Otherwise, provide
371 * an object.
372 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
373 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
374 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
375 * @param {string|number} [value.fractional] Up to six digits for microsecond
376 * precision.
377 *
378 * @example
379 * ```
380 * const {BigQuery} = require('@google-cloud/bigquery');
381 * const time = BigQuery.time('14:00:00'); // 2:00 PM
382 *
383 * //-
384 * // Alternatively, provide an object.
385 * //-
386 * const time = BigQuery.time({
387 * hours: 14,
388 * minutes: 0,
389 * seconds: 0
390 * });
391 * ```
392 */
393 /**
394 * A `TIME` data type represents a time, independent of a specific date.
395 *
396 * @param {object|string} value The time. If a string, this should be in the
397 * format the API describes: `[H]H:[M]M:[S]S[.DDDDDD]`. Otherwise, provide
398 * an object.
399 * @param {string|number} [value.hours] One or two digits (`00` - `23`).
400 * @param {string|number} [value.minutes] One or two digits (`00` - `59`).
401 * @param {string|number} [value.seconds] One or two digits (`00` - `59`).
402 * @param {string|number} [value.fractional] Up to six digits for microsecond
403 * precision.
404 *
405 * @example
406 * ```
407 * const {BigQuery} = require('@google-cloud/bigquery');
408 * const bigquery = new BigQuery();
409 * const time = bigquery.time('14:00:00'); // 2:00 PM
410 *
411 * //-
412 * // Alternatively, provide an object.
413 * //-
414 * const time = bigquery.time({
415 * hours: 14,
416 * minutes: 0,
417 * seconds: 0
418 * });
419 * ```
420 */
421 static time(value: BigQueryTimeOptions | string): BigQueryTime;
422 time(value: BigQueryTimeOptions | string): BigQueryTime;
423 /**
424 * A timestamp represents an absolute point in time, independent of any time
425 * zone or convention such as Daylight Savings Time.
426 *
427 * @method BigQuery.timestamp
428 * @param {Date|string} value The time.
429 *
430 * @example
431 * ```
432 * const {BigQuery} = require('@google-cloud/bigquery');
433 * const timestamp = BigQuery.timestamp(new Date());
434 * ```
435 */
436 /**
437 * A timestamp represents an absolute point in time, independent of any time
438 * zone or convention such as Daylight Savings Time.
439 *
440 * @param {Date|string} value The time.
441 *
442 * @example
443 * ```
444 * const {BigQuery} = require('@google-cloud/bigquery');
445 * const bigquery = new BigQuery();
446 * const timestamp = bigquery.timestamp(new Date());
447 * ```
448 */
449 static timestamp(value: Date | string): BigQueryTimestamp;
450 timestamp(value: Date | string): BigQueryTimestamp;
451 /**
452 * A BigQueryInt wraps 'INT64' values. Can be used to maintain precision.
453 *
454 * @param {string|number|IntegerTypeCastValue} value The INT64 value to convert.
455 * @param {IntegerTypeCastOptions} typeCastOptions Configuration to convert
456 * value. Must provide an `integerTypeCastFunction` to handle conversion.
457 * @returns {BigQueryInt}
458 *
459 * @example
460 * ```
461 * const {BigQuery} = require('@google-cloud/bigquery');
462 * const bigquery = new BigQuery();
463 *
464 * const largeIntegerValue = Number.MAX_SAFE_INTEGER + 1;
465 *
466 * const options = {
467 * integerTypeCastFunction: value => value.split(),
468 * };
469 *
470 * const bqInteger = bigquery.int(largeIntegerValue, options);
471 *
472 * const customValue = bqInteger.valueOf();
473 * // customValue is the value returned from your `integerTypeCastFunction`.
474 * ```
475 */
476 static int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
477 int(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions): BigQueryInt;
478 /**
479 * A geography value represents a surface area on the Earth
480 * in Well-known Text (WKT) format.
481 *
482 * @param {string} value The geospatial data.
483 *
484 * @example
485 * ```
486 * const {BigQuery} = require('@google-cloud/bigquery');
487 * const bigquery = new BigQuery();
488 * const geography = bigquery.geography('POINT(1, 2)');
489 * ```
490 */
491 static geography(value: string): Geography;
492 geography(value: string): Geography;
493 /**
494 * Convert an INT64 value to Number.
495 *
496 * @private
497 * @param {object} value The INT64 value to convert.
498 */
499 static decodeIntegerValue_(value: IntegerTypeCastValue): number;
500 /**
501 * Return a value's provided type.
502 *
503 * @private
504 *
505 * @throws {error} If the type provided is invalid.
506 *
507 * See {@link https://cloud.google.com/bigquery/data-types| Data Type}
508 *
509 * @param {*} providedType The type.
510 * @returns {string} The valid type provided.
511 */
512 static getTypeDescriptorFromProvidedType_(providedType: string | ProvidedTypeStruct | ProvidedTypeArray): ValueType;
513 /**
514 * Detect a value's type.
515 *
516 * @private
517 *
518 * @throws {error} If the type could not be detected.
519 *
520 * See {@link https://cloud.google.com/bigquery/data-types| Data Type}
521 *
522 * @param {*} value The value.
523 * @returns {string} The type detected from the value.
524 */
525 static getTypeDescriptorFromValue_(value: unknown): ValueType;
526 /**
527 * Convert a value into a `queryParameter` object.
528 *
529 * @private
530 *
531 * See {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#request-body| Jobs.query API Reference Docs (see `queryParameters`)}
532 *
533 * @param {*} value The value.
534 * @param {string|ProvidedTypeStruct|ProvidedTypeArray} providedType Provided
535 * query parameter type.
536 * @returns {object} A properly-formed `queryParameter` object.
537 */
538 static valueToQueryParameter_(value: any, providedType?: string | ProvidedTypeStruct | ProvidedTypeArray): bigquery.IQueryParameter;
539 private static _getValue;
540 private static _isCustomType;
541 /**
542 * @callback DatasetCallback
543 * @param {?Error} err Request error, if any.
544 * @param {object} dataset The [dataset resource]{@link https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#resource}.
545 * @param {object} apiResponse The full API response.
546 */
547 /**
548 * Create a dataset.
549 *
550 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/insert| Datasets: insert API Documentation}
551 *
552 * @param {string} id ID of the dataset to create.
553 * @param {object} [options] See a
554 * {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets#resource| Dataset resource}.
555 * @param {DatasetCallback} [callback] The callback function.
556 * @param {?error} callback.err An error returned while making this request
557 * @param {Dataset} callback.dataset The newly created dataset
558 * @param {object} callback.apiResponse The full API response.
559 *
560 * @example
561 * ```
562 * const {BigQuery} = require('@google-cloud/bigquery');
563 * const bigquery = new BigQuery();
564 *
565 * bigquery.createDataset('my-dataset', function(err, dataset, apiResponse)
566 * {});
567 *
568 * //-
569 * // If the callback is omitted, we'll return a Promise.
570 * //-
571 * bigquery.createDataset('my-dataset').then(function(data) {
572 * const dataset = data[0];
573 * const apiResponse = data[1];
574 * });
575 * ```
576 */
577 createDataset(id: string, options?: DatasetResource): Promise<DatasetResponse>;
578 createDataset(id: string, options: DatasetResource, callback: DatasetCallback): void;
579 createDataset(id: string, callback: DatasetCallback): void;
580 /**
581 * @callback JobCallback
582 * @param {?Error} err Request error, if any.
583 * @param {object} job The newly created job for your query.
584 * @param {object} apiResponse The full API response.
585 */
586 /**
587 * Run a query as a job. No results are immediately returned. Instead, your
588 * callback will be executed with a {@link Job} object that you must
589 * ping for the results. See the Job documentation for explanations of how to
590 * check on the status of the job.
591 *
592 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert| Jobs: insert API Documentation}
593 *
594 * @param {object|string} options The configuration object. This must be in
595 * the format of the {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job#JobConfigurationQuery| `configuration.query`}
596 * property of a Jobs resource. If a string is provided, this is used as the
597 * query string, and all other options are defaulted.
598 * @param {Table} [options.destination] The table to save the
599 * query's results to. If omitted, a new table will be created.
600 * @param {boolean} [options.dryRun] If set, don't actually run this job. A
601 * valid query will update the job with processing statistics. These can
602 * be accessed via `job.metadata`.
603 * @param {object} [options.labels] String key/value pairs to be attached as
604 * labels to the newly created Job.
605 * @param {string} [options.location] The geographic location of the job.
606 * Required except for US and EU.
607 * @param {number} [options.jobTimeoutMs] Job timeout in milliseconds.
608 * If this time limit is exceeded, BigQuery might attempt to stop the job.
609 * @param {string} [options.jobId] Custom job id.
610 * @param {string} [options.jobPrefix] Prefix to apply to the job id.
611 * @param {string} options.query A query string, following the BigQuery query
612 * syntax, of the query to execute.
613 * @param {boolean} [options.useLegacySql=false] Option to use legacy sql syntax.
614 * @param {object} [options.defaultDataset] The dataset. This must be in
615 * the format of the {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/datasets#DatasetReference| `DatasetReference`}
616 * @param {boolean} [options.wrapIntegers] Optionally wrap INT64 in BigQueryInt
617 * or custom INT64 value type.
618 * @param {object|array} [options.params] Option to provide query prarameters.
619 * @param {JobCallback} [callback] The callback function.
620 * @param {?error} callback.err An error returned while making this request.
621 * @param {Job} callback.job The newly created job for your query.
622 * @param {object} callback.apiResponse The full API response.
623 *
624 * @throws {Error} If a query is not specified.
625 * @throws {Error} If a Table is not provided as a destination.
626 *
627 * @example
628 * ```
629 * const {BigQuery} = require('@google-cloud/bigquery');
630 * const bigquery = new BigQuery();
631 *
632 * const query = 'SELECT url FROM `publicdata.samples.github_nested` LIMIT
633 * 100';
634 *
635 * //-
636 * // You may pass only a query string, having a new table created to store
637 * the
638 * // results of the query.
639 * //-
640 * bigquery.createQueryJob(query, function(err, job) {});
641 *
642 * //-
643 * // You can also control the destination table by providing a
644 * // {@link Table} object.
645 * //-
646 * bigquery.createQueryJob({
647 * destination: bigquery.dataset('higher_education').table('institutions'),
648 * query: query
649 * }, function(err, job) {});
650 *
651 * //-
652 * // After you have run `createQueryJob`, your query will execute in a job.
653 * Your
654 * // callback is executed with a {@link Job} object so that you may
655 * // check for the results.
656 * //-
657 * bigquery.createQueryJob(query, function(err, job) {
658 * if (!err) {
659 * job.getQueryResults(function(err, rows, apiResponse) {});
660 * }
661 * });
662 *
663 * //-
664 * // If the callback is omitted, we'll return a Promise.
665 * //-
666 * bigquery.createQueryJob(query).then(function(data) {
667 * const job = data[0];
668 * const apiResponse = data[1];
669 *
670 * return job.getQueryResults();
671 * });
672 * ```
673 */
674 createQueryJob(options: Query | string): Promise<JobResponse>;
675 createQueryJob(options: Query | string, callback: JobCallback): void;
676 /**
677 * Creates a job. Typically when creating a job you'll have a very specific
678 * task in mind. For this we recommend one of the following methods:
679 *
680 * - {@link BigQuery.createQueryJob}
681 * - {@link Table#createCopyJob}
682 * - {@link Table#createCopyFromJob}
683 * - {@link Table#createExtractJob}
684 * - {@link Table#createLoadJob}
685 *
686 * However in the event you need a finer level of control over the job
687 * creation, you can use this method to pass in a raw {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job| Job resource}
688 * object.
689 *
690 * See {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/jobs| Jobs Overview}
691 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/insert| Jobs: insert API Documentation}
692 *
693 * @param {object} options Object in the form of a {@link https://cloud.google.com/bigquery/docs/reference/rest/v2/Job| Job resource};
694 * @param {string} [options.jobId] Custom job id.
695 * @param {string} [options.jobPrefix] Prefix to apply to the job id.
696 * @param {string} [options.location] The geographic location of the job.
697 * Required except for US and EU.
698 * @param {JobCallback} [callback] The callback function.
699 * @param {?error} callback.err An error returned while making this request.
700 * @param {Job} callback.job The newly created job.
701 * @param {object} callback.apiResponse The full API response.
702 *
703 * @example
704 * ```
705 * const {BigQuery} = require('@google-cloud/bigquery');
706 * const bigquery = new BigQuery();
707 *
708 * const options = {
709 * configuration: {
710 * query: {
711 * query: 'SELECT url FROM `publicdata.samples.github_nested` LIMIT 100'
712 * }
713 * }
714 * };
715 *
716 * bigquery.createJob(options, function(err, job) {
717 * if (err) {
718 * // Error handling omitted.
719 * }
720 *
721 * job.getQueryResults(function(err, rows) {});
722 * });
723 *
724 * //-
725 * // If the callback is omitted, we'll return a Promise.
726 * //-
727 * bigquery.createJob(options).then(function(data) {
728 * const job = data[0];
729 *
730 * return job.getQueryResults();
731 * });
732 * ```
733 */
734 createJob(options: JobOptions): Promise<JobResponse>;
735 createJob(options: JobOptions, callback: JobCallback): void;
736 /**
737 * Create a reference to a dataset.
738 *
739 * @param {string} id ID of the dataset.
740 * @param {object} [options] Dataset options.
741 * @param {string} [options.location] The geographic location of the dataset.
742 * Required except for US and EU.
743 *
744 * @example
745 * ```
746 * const {BigQuery} = require('@google-cloud/bigquery');
747 * const bigquery = new BigQuery();
748 * const dataset = bigquery.dataset('higher_education');
749 * ```
750 */
751 dataset(id: string, options?: DatasetOptions): Dataset;
752 /**
753 * List all or some of the datasets in your project.
754 *
755 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/datasets/list| Datasets: list API Documentation}
756 *
757 * @param {object} [options] Configuration object.
758 * @param {boolean} [options.all] List all datasets, including hidden ones.
759 * @param {boolean} [options.autoPaginate] Have pagination handled automatically.
760 * Default: true.
761 * @param {number} [options.maxApiCalls] Maximum number of API calls to make.
762 * @param {number} [options.maxResults] Maximum number of results to return.
763 * @param {string} [options.pageToken] Token returned from a previous call, to
764 * request the next page of results.
765 * @param {DatasetsCallback} [callback] The callback function.
766 * @param {?error} callback.err An error returned while making this request
767 * @param {Dataset[]} callback.datasets The list of datasets in your project.
768 *
769 * @example
770 * ```
771 * const {BigQuery} = require('@google-cloud/bigquery');
772 * const bigquery = new BigQuery();
773 *
774 * bigquery.getDatasets(function(err, datasets) {
775 * if (!err) {
776 * // datasets is an array of Dataset objects.
777 * }
778 * });
779 *
780 * //-
781 * // To control how many API requests are made and page through the results
782 * // manually, set `autoPaginate` to `false`.
783 * //-
784 * function manualPaginationCallback(err, datasets, nextQuery, apiResponse) {
785 * if (nextQuery) {
786 * // More results exist.
787 * bigquery.getDatasets(nextQuery, manualPaginationCallback);
788 * }
789 * }
790 *
791 * bigquery.getDatasets({
792 * autoPaginate: false
793 * }, manualPaginationCallback);
794 *
795 * //-
796 * // If the callback is omitted, we'll return a Promise.
797 * //-
798 * bigquery.getDatasets().then(function(datasets) {});
799 * ```
800 */
801 getDatasets(options?: GetDatasetsOptions): Promise<DatasetsResponse>;
802 getDatasets(options: GetDatasetsOptions, callback: DatasetsCallback): void;
803 getDatasets(callback: DatasetsCallback): void;
804 /**
805 * @callback GetJobsCallback
806 * @param {?Error} err Request error, if any.
807 * @param {object} jobs An array of [Job]{@link https://cloud.google.com/bigquery/docs/reference/v2/Job} objects.
808 */
809 /**
810 * @typedef {array} GetJobsResponse
811 * @property {object} 0 An array of Job objects.
812 */
813 /**
814 * Get all of the jobs from your project.
815 *
816 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/list| Jobs: list API Documentation}
817 *
818 * @param {object} [options] Configuration object.
819 * @param {boolean} [options.allUsers] Display jobs owned by all users in the
820 * project.
821 * @param {boolean} [options.autoPaginate] Have pagination handled
822 * automatically. Default: true.
823 * @param {number} [options.maxApiCalls] Maximum number of API calls to make.
824 * @param {number} [options.maxResults] Maximum number of results to return.
825 * @param {string} [options.pageToken] Token returned from a previous call, to
826 * request the next page of results.
827 * @param {string} [options.projection] Restrict information returned to a set
828 * of selected fields. Acceptable values are "full", for all job data, and
829 * "minimal", to not include the job configuration.
830 * @param {string} [options.stateFilter] Filter for job state. Acceptable
831 * values are "done", "pending", and "running". Sending an array to this
832 * option performs a disjunction.
833 * @param {GetJobsCallback} [callback] The callback function.
834 * @param {?error} callback.err An error returned while making this request
835 * @param {Job[]} callback.jobs The list of jobs in your
836 * project.
837 *
838 * @example
839 * ```
840 * const {BigQuery} = require('@google-cloud/bigquery');
841 * const bigquery = new BigQuery();
842 *
843 * bigquery.getJobs(function(err, jobs) {
844 * if (!err) {
845 * // jobs is an array of Job objects.
846 * }
847 * });
848 *
849 * //-
850 * // To control how many API requests are made and page through the results
851 * // manually, set `autoPaginate` to `false`.
852 * //-
853 * function manualPaginationCallback(err, jobs, nextQuery, apiRespose) {
854 * if (nextQuery) {
855 * // More results exist.
856 * bigquery.getJobs(nextQuery, manualPaginationCallback);
857 * }
858 * }
859 *
860 * bigquery.getJobs({
861 * autoPaginate: false
862 * }, manualPaginationCallback);
863 *
864 * //-
865 * // If the callback is omitted, we'll return a Promise.
866 * //-
867 * bigquery.getJobs().then(function(data) {
868 * const jobs = data[0];
869 * });
870 * ```
871 */
872 getJobs(options?: GetJobsOptions): Promise<GetJobsResponse>;
873 getJobs(options: GetJobsOptions, callback: GetJobsCallback): void;
874 getJobs(callback: GetJobsCallback): void;
875 /**
876 * Create a reference to an existing job.
877 *
878 * @param {string} id ID of the job.
879 * @param {object} [options] Configuration object.
880 * @param {string} [options.location] The geographic location of the job.
881 * Required except for US and EU.
882 *
883 * @example
884 * ```
885 * const {BigQuery} = require('@google-cloud/bigquery');
886 * const bigquery = new BigQuery();
887 *
888 * const myExistingJob = bigquery.job('job-id');
889 * ```
890 */
891 job(id: string, options?: JobOptions): Job;
892 /**
893 * Run a query scoped to your project. For manual pagination please refer to
894 * {@link BigQuery.createQueryJob}.
895 *
896 * See {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/query| Jobs: query API Documentation}
897 *
898 * @param {string|object} query A string SQL query or configuration object.
899 * For all available options, see
900 * {@link https://cloud.google.com/bigquery/docs/reference/v2/jobs/query#request-body| Jobs: query request body}.
901 * @param {string} [query.location] The geographic location of the job.
902 * Required except for US and EU.
903 * @param {string} [query.jobId] Custom id for the underlying job.
904 * @param {string} [query.jobPrefix] Prefix to apply to the underlying job id.
905 * @param {object|Array<*>} query.params For positional SQL parameters, provide
906 * an array of values. For named SQL parameters, provide an object which
907 * maps each named parameter to its value. The supported types are
908 * integers, floats, {@link BigQuery.date} objects, {@link BigQuery.datetime}
909 * objects, {@link BigQuery.time} objects, {@link BigQuery.timestamp}
910 * objects, Strings, Booleans, and Objects.
911 * @param {string} query.query A query string, following the BigQuery query
912 * syntax, of the query to execute.
913 * @param {object|Array<*>} query.types Provided types for query parameters.
914 * For positional SQL parameters, provide an array of types. For named
915 * SQL parameters, provide an object which maps each named parameter to
916 * its type.
917 * @param {boolean} [query.useLegacySql=false] Option to use legacy sql syntax.
918 * @param {object} [options] Configuration object for query results.
919 * @param {number} [options.maxResults] Maximum number of results to read.
920 * @param {number} [options.timeoutMs] How long to wait for the query to
921 * complete, in milliseconds, before returning. Default is 10 seconds.
922 * If the timeout passes before the job completes, an error will be returned
923 * and the 'jobComplete' field in the response will be false.
924 * @param {boolean|IntegerTypeCastOptions} [options.wrapIntegers=false] Wrap values
925 * of 'INT64' type in {@link BigQueryInt} objects.
926 * If a `boolean`, this will wrap values in {@link BigQueryInt} objects.
927 * If an `object`, this will return a value returned by
928 * `wrapIntegers.integerTypeCastFunction`.
929 * Please see {@link IntegerTypeCastOptions} for options descriptions.
930 * @param {function} [callback] The callback function.
931 * @param {?error} callback.err An error returned while making this request
932 * @param {array} callback.rows The list of results from your query.
933 *
934 * @example
935 * ```
936 * const {BigQuery} = require('@google-cloud/bigquery');
937 * const bigquery = new BigQuery();
938 *
939 * const query = 'SELECT url FROM `publicdata.samples.github_nested` LIMIT
940 * 100';
941 *
942 * bigquery.query(query, function(err, rows) {
943 * if (!err) {
944 * // rows is an array of results.
945 * }
946 * });
947 *
948 * //-
949 * // Positional SQL parameters are supported.
950 * //-
951 * bigquery.query({
952 * query: [
953 * 'SELECT url',
954 * 'FROM `publicdata.samples.github_nested`',
955 * 'WHERE repository.owner = ?'
956 * ].join(' '),
957 *
958 * params: [
959 * 'google'
960 * ]
961 * }, function(err, rows) {});
962 *
963 * //-
964 * // Or if you prefer to name them, that's also supported.
965 * //-
966 * bigquery.query({
967 * query: [
968 * 'SELECT url',
969 * 'FROM `publicdata.samples.github_nested`',
970 * 'WHERE repository.owner = @owner'
971 * ].join(' '),
972 * params: {
973 * owner: 'google'
974 * }
975 * }, function(err, rows) {});
976 *
977 * //-
978 * // Providing types for SQL parameters is supported.
979 * //-
980 * bigquery.query({
981 * query: [
982 * 'SELECT url',
983 * 'FROM `publicdata.samples.github_nested`',
984 * 'WHERE repository.owner = ?'
985 * ].join(' '),
986 *
987 * params: [
988 * null
989 * ],
990 *
991 * types: ['string']
992 * }, function(err, rows) {});
993 *
994 * //-
995 * // If you need to use a `DATE`, `DATETIME`, `TIME`, or `TIMESTAMP` type in
996 * // your query, see {@link BigQuery.date}, {@link BigQuery.datetime},
997 * // {@link BigQuery.time}, and {@link BigQuery.timestamp}.
998 * //-
999 *
1000 * //-
1001 * // If the callback is omitted, we'll return a Promise.
1002 * //-
1003 * bigquery.query(query).then(function(data) {
1004 * const rows = data[0];
1005 * });
1006 * ```
1007 */
1008 query(query: string, options?: QueryOptions): Promise<QueryRowsResponse>;
1009 query(query: Query, options?: QueryOptions): Promise<SimpleQueryRowsResponse>;
1010 query(query: string, options: QueryOptions, callback?: QueryRowsCallback): void;
1011 query(query: Query, options: QueryOptions, callback?: SimpleQueryRowsCallback): void;
1012 query(query: string, callback?: QueryRowsCallback): void;
1013 query(query: Query, callback?: SimpleQueryRowsCallback): void;
1014 /**
1015 * This method will be called by `createQueryStream()`. It is required to
1016 * properly set the `autoPaginate` option value.
1017 *
1018 * @private
1019 */
1020 queryAsStream_(query: Query, callback?: SimpleQueryRowsCallback): void;
1021}
1022/**
1023 * Date class for BigQuery.
1024 */
1025export declare class BigQueryDate {
1026 value: string;
1027 constructor(value: BigQueryDateOptions | string);
1028}
1029/**
1030 * Geography class for BigQuery.
1031 */
1032export declare class Geography {
1033 value: string;
1034 constructor(value: string);
1035}
1036/**
1037 * Timestamp class for BigQuery.
1038 */
1039export declare class BigQueryTimestamp {
1040 value: string;
1041 constructor(value: Date | string);
1042}
1043/**
1044 * Datetime class for BigQuery.
1045 */
1046export declare class BigQueryDatetime {
1047 value: string;
1048 constructor(value: BigQueryDatetimeOptions | string);
1049}
1050/**
1051 * Time class for BigQuery.
1052 */
1053export declare class BigQueryTime {
1054 value: string;
1055 constructor(value: BigQueryTimeOptions | string);
1056}
1057/**
1058 * Build a BigQueryInt object. For long integers, a string can be provided.
1059 *
1060 * @class
1061 * @param {string|number|IntegerTypeCastValue} value The 'INT64' value.
1062 * @param {object} [typeCastOptions] Configuration to convert
1063 * values of 'INT64' type to a custom value. Must provide an
1064 * `integerTypeCastFunction` to handle conversion.
1065 * @param {function} typeCastOptions.integerTypeCastFunction A custom user
1066 * provided function to convert value.
1067 * @param {string|string[]} [typeCastOptions.fields] Schema field
1068 * names to be converted using `integerTypeCastFunction`.
1069 *
1070 * @example
1071 * ```
1072 * const {BigQuery} = require('@google-cloud/bigquery');
1073 * const bigquery = new BigQuery();
1074 * const anInt = bigquery.int(7);
1075 * ```
1076 */
1077export declare class BigQueryInt extends Number {
1078 type: string;
1079 value: string;
1080 typeCastFunction?: Function;
1081 private _schemaFieldName;
1082 constructor(value: string | number | IntegerTypeCastValue, typeCastOptions?: IntegerTypeCastOptions);
1083 valueOf(): any;
1084 toJSON(): Json;
1085}
1086export interface Json {
1087 [field: string]: string;
1088}
1089
\No newline at end of file