Back to results
minodisk/zoq(opens in a new tab)
Language: TypeScript
Convert Zod to BigQuery Schema
- stars
- 9
- watchers
- 1
- forks
- 0
- open issues
- 0
- Last updated
- 01/17/2023
Language: TypeScript
Convert Zod to BigQuery Schema
Convert Zod to BigQuery Schema.
npm install -S zoq
import { BigQuery } from "@google-cloud/bigquery"; import { z } from "zod"; import { convert, RegExpDate, RegExpTime } from "zoq"; async function createTable() { const definition = z.object({ bool: z.boolean().nullable(), numeric: z.number().nullable(), int64: z.number().int().nullable(), bigint: z.bigint().nullable(), string: z.string().nullable(), timestamp: z.date().nullable(), date: z.string().regex(RegExpDate).nullable(), time: z.string().regex(RegExpTime).nullable(), }); const schema = convert(definition); console.log(schema); // outputs -> [ // { name: "bool", type: "BOOL", mode: "NULLABLE" }, // { name: "numeric", type: "NUMERIC", mode: "NULLABLE" }, // { name: "int64", type: "INT64", mode: "NULLABLE" }, // { name: "bigint", type: "BIGNUMERIC", mode: "NULLABLE" }, // { name: "string", type: "STRING", mode: "NULLABLE" }, // { name: "timestamp", type: "TIMESTAMP", mode: "NULLABLE" }, // { name: "date", type: "DATE", mode: "NULLABLE" }, // { name: "time", type: "TIME", mode: "NULLABLE" }, // ]; await new BigQuery() .dataset("dataset_id") .createTable("table_id", { schema }); }