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.