0.0.7 • Published 1 year ago

zoq v0.0.7

Weekly downloads
-
License
Apache-2
Repository
github
Last release
1 year ago

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

1 year ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.1

2 years ago

1.0.0

7 years ago