# prisma-to-zod

> Generate Zod validation schema from a Prisma schema.

Latest version **0.2.4** (published 2023-02-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install prisma-to-zod
pnpm add prisma-to-zod
yarn add prisma-to-zod
bun add prisma-to-zod
```

Provides the commands `p2z`, `prisma-to-zod`.

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.2.4 |
| Published | 2023-02-06 |
| First published | 2022-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 2 |
| Unpacked size | 8.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Andreas Söderlund |
| Maintainers | ciscoheat |
| Keywords | prisma, zod, validation, schema, generator |

## Links

- npm: https://www.npmjs.com/package/prisma-to-zod
- Repository: https://github.com/ciscoheat/prisma-to-zod
- Homepage: https://github.com/ciscoheat/prisma-to-zod#readme
- Issues: https://github.com/ciscoheat/prisma-to-zod/issues
- npm.io page: https://npm.io/package/prisma-to-zod

## Dependencies (2)

- [minimist](https://npm.io/package/minimist.md) ^1.2.7
- [ansi-colors](https://npm.io/package/ansi-colors.md) ^4.1.3

## Alternatives

- [@regle/core](https://npm.io/package/@regle/core.md) — 47.0K weekly downloads
- [typeof-arguments](https://npm.io/package/typeof-arguments.md) — 12.5K weekly downloads
- [@lokalise/projects-engine-contracts](https://npm.io/package/@lokalise/projects-engine-contracts.md) — 978 weekly downloads
- [@osjwnpm/nam-laboriosam-quibusdam](https://npm.io/package/@osjwnpm/nam-laboriosam-quibusdam.md) — 70 weekly downloads
- [@oridune/validator](https://npm.io/package/@oridune/validator.md) — 16 weekly downloads

## Recent versions

- 0.2.4 (latest) — 2023-02-06
- 0.2.3 — 2023-01-22
- 0.2.2 — 2023-01-22
- 0.2.1 — 2022-11-27
- 0.2.0 — 2022-11-27
- 0.1.1 — 2022-11-25
- 0.1.0 — 2022-11-25

## README

# prisma-to-zod

Simple generator of [Zod](https://zod.dev/) validation schemas from [Prisma](https://www.prisma.io/) 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

```bash
(p)npm install -D prisma-to-zod
```

## Usage

```bash
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

```js
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](https://www.prisma.io/docs/concepts/components/prisma-schema/generators)

Suggestions, improvements, PRs, are welcome at the [github repo](https://github.com/ciscoheat/prisma-to-zod).

---
_Source: https://npm.io/package/prisma-to-zod · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
