0.2.4 • Published 1 year ago

prisma-to-zod v0.2.4

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

prisma-to-zod

Simple generator of Zod validation schemas from Prisma schemas.

The generated file exports schemas according to the name of the Prisma models, with type guards for missing keys when the schema evolves.

Installation

(p)npm install -D prisma-to-zod

Usage

p2z prisma/schema.prisma [output.ts]

Will generate a typescript file, ready for additional validations. If no output file is specified, the schema will be written to stdout.

NOTE: This should currently be regarded as a one-step process, since any additional generation will overwrite your modifications. A future version will update the schema without overwriting.

Programmatically

import { prismaToZod } from "prisma-to-zod";
import fs from "fs";

const schema = fs.readFileSync("prisma/schema.prisma", { encoding: "utf8" });

console.log(prismaToZod(schema));

Goals

  • Parse and update generated schema file instead of overwriting
  • Make library into a real Prisma generator

Suggestions, improvements, PRs, are welcome at the github repo.

0.2.3

1 year ago

0.2.2

1 year ago

0.2.4

1 year ago

0.2.1

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.1.0

1 year ago