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