UNPKG

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