UNPKG

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