Registry / database / drizzle-zod-codegen

drizzle-zod-codegen

JSON →
library0.2.0jsnpmunverified

CLI and programmatic tool to generate static Zod schema files from Drizzle ORM table definitions. Current version 0.2.0, actively maintained with weekly releases. Differs from runtime drizzle-zod adapters by emitting inspectable, version-controllable .zod.ts files that can be tree-shaken. Supports PostgreSQL, MySQL, SQLite, SingleStore, and expands Zod constructs (discriminated unions, intersections, pipelines, readonly, symbol, NaN, catch). Handles SelectSchema, InsertSchema, UpdateSchema variants. Requires Node >=18, peer dependencies drizzle-orm >=0.36.0 and zod ^3.25.0 || ^4.0.0.

npm install drizzle-zod-codegen
INSTALL
IMPORT
SIG · DRIZZLE-ZOD-CODEGE
D
drizzle-zod-codegen
databasejavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generate
import { generate } from 'drizzle-zod-codegen'
const generate = require('drizzle-zod-codegen')
ESM-only since v0.2.0; CommonJS require will fail.
generateSchemas
import { generateSchemas } from 'drizzle-zod-codegen/generator'
import { generateSchemas } from 'drizzle-zod-codegen'
generateSchemas is exported from a subpath; not in main entry.
DrizzleZodCodegenConfig
import type { DrizzleZodCodegenConfig } from 'drizzle-zod-codegen'
Type import is safe; also available as a named type export.

Generate static Zod schema files from Drizzle ORM table schemas using the CLI or programmatic API.

// 1. Generate Zod schemas from Drizzle schema files // npx drizzle-zod-codegen generate src/schema.ts --output ./ // 2. Programmatic usage import { generate } from 'drizzle-zod-codegen'; const result = await generate({ input: ['src/schema.ts'], outDir: './zod', }); console.log(result); // { written: ['zod/users.zod.ts', ...] } // 3. Generated file example (users.zod.ts) import { z } from 'zod'; export const usersSelectSchema = z.object({ id: z.number(), name: z.string(), email: z.string().email(), createdAt: z.date(), }); export const usersInsertSchema = usersSelectSchema.omit({ id: true }); export const usersUpdateSchema = usersSelectSchema.partial();
Debug
Known issues
breakingDynamic defaults or catch fallbacks (e.g., .default(() => Math.random())) will cause the generator to throw an error; they must be replaced with static values or moved to runtime post-processing.
fix
Replace with deterministic defaults like .default('hello') or post-process the generated .zod.ts file to add the dynamic default manually.
affects: >=0.2.0
deprecatedThe old `--single` output mode (single bundle file) may be deprecated in future versions; prefer `--output single` which is the same, but check changelog.
fix
Use `--output single` explicitly; ensure you are on latest version.
affects: 0.2.0
gotchaUnsupported Zod constructs like z.function(), z.custom(), .refine(), .superRefine() will throw instead of falling back to z.any(). This is intentional to avoid silent weakening.
fix
Avoid using those constructs in Drizzle schemas if you need full codegen support; or post-process the generated file.
affects: >=0.2.0
breakingESM-only package: requires Node >=18 and "type": "module" in package.json or .mjs extension. CommonJS require() will throw.
fix
Switch to ESM imports or use dynamic import() if needed in CJS project.
affects: >=0.2.0
deprecatedThe `generateSchemas` function is exported from the subpath `drizzle-zod-codegen/generator` – the main entry may remove it in future versions.
fix
Import from 'drizzle-zod-codegen/generator' explicitly.
affects: 0.2.0
Errors
Common errors & fixes
Cannot find module 'drizzle-zod-codegen'
Package not installed; or installed as devDependency but not in node_modules.
fix
Run `npm install -D drizzle-zod-codegen` (or pnpm/yarn equivalent). Ensure it is in devDependencies.
Unsupported Zod type: z.function
Drizzle schema uses z.function() which cannot be statically serialized.
fix
Remove or replace z.function() from your Drizzle schema; or post-process the generated .zod.ts file to add the function manually.
ZodDefault uses a dynamic factory
`.default(() => ...)` with a dynamic (non-deterministic) factory cannot be serialized.
fix
Replace with a static default value like `.default('hello')`, or post-process after generation.
Cannot find module 'drizzle-orm'
Peer dependency drizzle-orm not installed.
fix
Run `npm install drizzle-orm` (version >=0.36.0).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
drizzle-ormrequiredPeer dependency; required to read Drizzle schema definitions for code generation
zodrequiredPeer dependency; generated schemas depend on Zod runtime for validation
Agent activity
7 hits · last 30 days
node
6
Resources
drizzle-zod-codegen — npm install drizzle-zod-codegen · libregistry