import { BigQuery } from "@google-cloud/bigquery"
export type DynSelect_dataset_id = string
// Dropdown of the datasets in the service account's project.
export async function dataset_id(auth: RT.Bigquery) {
const [datasets] = await client(auth).getDatasets()
return datasets.map((d) => ({ value: d.id!, label: d.id! }))
}
function client(auth: RT.Bigquery) {
return new BigQuery({ credentials: auth, projectId: auth.project_id })
}
/**
* Get Table Schema
* Get a BigQuery table's columns (name, type, mode, description, nested fields) along with its row count, size and partitioning.
*/
export async function main(
auth: RT.Bigquery,
dataset_id: DynSelect_dataset_id,
table_id: string
) {
const [metadata] = await client(auth)
.dataset(dataset_id)
.table(table_id)
.getMetadata()
return {
table_id: metadata.tableReference.tableId,
type: metadata.type,
schema: metadata.schema,
num_rows: metadata.numRows,
num_bytes: metadata.numBytes,
time_partitioning: metadata.timePartitioning,
clustering: metadata.clustering,
description: metadata.description,
}
}
Submitted by hugo989 4 hours ago