0

Bigquery Insert Rows

by
Published Jul 17, 2024

Inserts rows into a BigQuery table. [See the docs](https://github.com/googleapis/nodejs-bigquery) and for an example [here](https://github.com/googleapis/nodejs-bigquery/blob/main/samples/insertRowsAsStream.js).

Script gcloud Verified

The script

Submitted by hugo697 Bun
Verified 692 days ago
1
import { BigQuery } from "@google-cloud/bigquery";
2

3
type Gcloud = {
4
  type: string;
5
  project_id: string;
6
  private_key_id: string;
7
  private_key: string;
8
  client_email: string;
9
  client_id: string;
10
  auth_uri: string;
11
  token_uri: string;
12
  auth_provider_x509_cert_url: string;
13
  client_x509_cert_url: string;
14
  universe_domain: string;
15
};
16

17
export async function main(
18
  resource: Gcloud,
19
  datasetId: string,
20
  tableId: string,
21
  rows: object[]
22
) {
23
  const bigQueryClient = new BigQuery({
24
    credentials: resource,
25
    projectId: resource.project_id,
26
  });
27

28
  const response = await bigQueryClient
29
    .dataset(datasetId)
30
    .table(tableId)
31
    .insert(rows);
32

33
  return response;
34
}
35