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