Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

minodisk/zoq

Open more actions menu

Repository files navigation

Zoq GitHub Actions NPM Codecov

Convert Zod to BigQuery Schema.

Installation

npm install -S zoq

Usage

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 });
}

Releases

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.