0

List Tables

by
Published today

List the tables and views in a BigQuery dataset.

Script bigquery Verified

The script

Submitted by hugo989 Bun
Verified 4 hours ago
1
import { BigQuery } from "@google-cloud/bigquery"
2

3
export type DynSelect_dataset_id = string
4

5
// Dropdown of the datasets in the service account's project.
6
export async function dataset_id(auth: RT.Bigquery) {
7
  const [datasets] = await client(auth).getDatasets()
8
  return datasets.map((d) => ({ value: d.id!, label: d.id! }))
9
}
10

11
function client(auth: RT.Bigquery) {
12
  return new BigQuery({ credentials: auth, projectId: auth.project_id })
13
}
14

15
/**
16
 * List Tables
17
 * List the tables and views in a BigQuery dataset, with their type and creation time.
18
 */
19
export async function main(
20
  auth: RT.Bigquery,
21
  dataset_id: DynSelect_dataset_id
22
) {
23
  const [tables] = await client(auth).dataset(dataset_id).getTables()
24
  return tables.map((t) => t.metadata)
25
}
26