UNPKG

3.02 kBTypeScriptView Raw
1/*!
2 * Copyright 2022 Google LLC. All Rights Reserved.
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/// <reference types="node" />
17import { RequestCallback, Table, InsertStreamOptions } from '.';
18import bigquery from './types';
19import { RowBatch } from './rowBatch';
20import { Stream } from 'stream';
21import { RowBatchOptions, InsertRowsOptions, RowMetadata } from './table';
22export interface MaxInsertOptions {
23 maxOutstandingRows: number;
24 maxOutstandingBytes: number;
25 maxDelayMillis: number;
26}
27export declare const defaultOptions: MaxInsertOptions;
28export declare type InsertRowsStreamResponse = bigquery.ITableDataInsertAllResponse;
29export declare type InsertRowsCallback = RequestCallback<bigquery.ITableDataInsertAllResponse | bigquery.ITable>;
30export interface InsertRow {
31 insertId?: string;
32 json?: bigquery.IJsonObject;
33}
34export declare type TableRow = bigquery.ITableRow;
35export interface PartialInsertFailure {
36 message: string;
37 reason: string;
38 row: RowMetadata;
39}
40/**
41 * Standard row queue used for inserting rows.
42 *
43 *
44 * @param {Table} table The table.
45 * @param {Duplex} dup Row stream.
46 * @param {InsertStreamOptions} options Insert and batch options.
47 */
48export declare class RowQueue {
49 table: Table;
50 stream: Stream;
51 insertRowsOptions: InsertRowsOptions;
52 batch: RowBatch;
53 batchOptions?: RowBatchOptions;
54 inFlight: boolean;
55 pending?: ReturnType<typeof setTimeout>;
56 constructor(table: Table, dup: Stream, options?: InsertStreamOptions);
57 /**
58 * Adds a row to the queue.
59 *
60 * @param {RowMetadata} row The row to insert.
61 * @param {InsertRowsCallback} callback The insert callback.
62 */
63 add(row: RowMetadata, callback: InsertRowsCallback): void;
64 /**
65 * Cancels any pending inserts and calls _insert immediately.
66 */
67 insert(callback?: InsertRowsCallback): void;
68 /**
69 * Accepts a batch of rows and inserts them into table.
70 *
71 * @param {object[]} rows The rows to insert.
72 * @param {InsertCallback[]} callbacks The corresponding callback functions.
73 * @param {function} [callback] Callback to be fired when insert is done.
74 */
75 _insert(rows: RowMetadata | RowMetadata[], callbacks: InsertRowsCallback[], cb?: InsertRowsCallback): void;
76 /**
77 * Sets the batching options.
78 *
79 *
80 * @param {RowBatchOptions} [options] The batching options.
81 */
82 setOptions(options?: RowBatchOptions): void;
83 getOptionDefaults(): RowBatchOptions;
84}