Generate Zod validation schemas from Drizzle ORM table definitions. Current stable version: 0.8.3, released alongside Drizzle ORM updates. Provides seamless integration with drizzle-orm and zod, allowing developers to define Zod schemas that mirror their database schema, reducing duplication and ensuring consistency. Differentiators: automatic generation of Zod schemas with proper types, support for custom filters and mutations, tight coupling with Drizzle ORM's table schema. Peer dependencies: zod ^3.25.0 || ^4.0.0, drizzle-orm >=0.36.0. Release cadence: tends to follow Drizzle ORM updates, with minor versions for feature additions and patches for fixes.
npm install drizzle-zodNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating insert and select Zod schemas from Drizzle SQLite table definition, then validates data with safeParse. Also shows custom field validations and coercion.
Use import syntax or set package.json "type": "module". Alternatively, use dynamic import: const { createInsertSchema } = await import('drizzle-zod');Use createUpdateSchema from drizzle-zod directly; avoid custom implementations.
Use the second argument to override field types: createInsertSchema(table, { field: z.string().optional() })Check generated schema and apply overrides for those fields using the second parameter.
Use z.infer to extract the type. Example: type InsertUser = z.infer<typeof insertUserSchema>;
Change to import statement: import { createInsertSchema } from 'drizzle-zod'; or use dynamic import in CJS.Run 'npm install drizzle-zod' and ensure it's in dependencies. Also install peer deps: 'npm install zod drizzle-orm'.
Override the field schema: createInsertSchema(table, { optionalField: z.string().optional() })Use z.coerce.number() on the field: createInsertSchema(table, { age: z.coerce.number() })