UNPKG

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