lucaconlaq/drizzle-zod-to-code(新しいタブで開きます)
主要言語: TypeScript
Generate Zod schemas (as code) from Drizzle ORM schemas
- star 数
- 14
- watcher 数
- 2
- fork 数
- 1
- issue 数
- 2
- 最終更新
- 2026/01/26
主要言語: TypeScript
Generate Zod schemas (as code) from Drizzle ORM schemas
Generate JavaScript/TypeScript code for Drizzle Zod schemas
This library was born in response to a need discussed in drizzle-orm issue #941: generating static validation schemas (i.e. Zod) from Drizzle ORM models without bundling Drizzle into the client.
zod-to-code.⚠️ Why dynamic Zod schemas are not always ideal
When sharing validation between server and client, using dynamic (runtime) Zod schemas, generated with drizzle-zod can lead to several issues:
Static schema generation avoids all of these issues.
npm i @lucaconlaq/drizzle-zod-to-code
npx drizzle-zod-to-code generate --out ../schemas/src/
--config <path> - Path to drizzle.config.ts (default: "drizzle.config.ts")--out <path> - Path for generated Zod schemas (default: "src/schemas")--ts-config <path> - Path to tsconfig.json (default: "tsconfig.json")-h, --help - Display help for commandYou can add it to your package.json scripts:
{
...
"scripts": {
...
"drizzle:generate": "drizzle-kit generate",
"drizzle:migrate": "drizzle-kit migrate",
"drizzle:push": "drizzle-kit push",
"drizzle:pull": "drizzle-kit pull",
"drizzle:studio": "drizzle-kit studio",
"drizzle:generate:zod": "drizzle-zod-to-code generate --out ../schemas/src/"
}
}Then you can run:
npm run drizzle:generate:zod
This is an initial release focused on the most common use cases. While it provides a solid foundation for generating static Zod schemas from Drizzle models, it does not cover all the use-cases that drizzle-zod support. If you find a bug, please consider contributing.
The test suite in test/drizzle/ mirrors the test suite of drizzle-zod. Here's a summary of the current test coverage across different databases:
| DB | Files | Total Tests | Skipped |
|---|---|---|---|
| 🐬 MySQL | mysqlTable, mysqlView, mysqlTypes, mysqlSchemaValidation |
21 | 13 |
| 🐘 Postgres | pgTable, pgView, pgTypes, pgSchemaValidation |
22 | 8 |
| 🪨 SQLite | sqliteTable, sqliteView, sqliteTypes, sqliteSchemaValidation |
18 | 13 |