{"id":40859,"library":"drizzle-zod","title":"drizzle-zod","description":"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.","status":"active","version":"0.8.3","language":"javascript","source_language":"en","source_url":"https://github.com/drizzle-team/drizzle-orm","tags":["javascript","zod","validate","validation","schema","drizzle","orm","pg","mysql","typescript"],"install":[{"cmd":"npm install drizzle-zod","lang":"bash","label":"npm"},{"cmd":"yarn add drizzle-zod","lang":"bash","label":"yarn"},{"cmd":"pnpm add drizzle-zod","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"runtime dependency for validation","package":"zod","optional":false},{"reason":"peer dependency required to resolve Drizzle table schema types","package":"drizzle-orm","optional":false}],"imports":[{"note":"ESM-only package; requires module type or .mjs extension. Use import statements.","wrong":"const createInsertSchema = require('drizzle-zod')","symbol":"createInsertSchema","correct":"import { createInsertSchema } from 'drizzle-zod'"},{"note":"All functions are exported from the main package. No subpath exports exist.","wrong":"import { createSelectSchema } from 'drizzle-zod/schemas'","symbol":"createSelectSchema","correct":"import { createSelectSchema } from 'drizzle-zod'"},{"note":"Function name is camelCase, not PascalCase.","wrong":"import { CreateUpdateSchema } from 'drizzle-zod'","symbol":"createUpdateSchema","correct":"import { createUpdateSchema } from 'drizzle-zod'"},{"note":"z is from zod, not from drizzle-zod. Common mistake is to import from wrong package.","wrong":"import { z } from 'drizzle-zod'","symbol":"z","correct":"import { z } from 'zod'"}],"quickstart":{"code":"import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core';\nimport { createInsertSchema, createSelectSchema } from 'drizzle-zod';\nimport { z } from 'zod';\n\nconst users = sqliteTable('users', {\n  id: integer('id').primaryKey(),\n  name: text('name').notNull(),\n  age: integer('age'),\n});\n\nconst insertUserSchema = createInsertSchema(users);\nconst selectUserSchema = createSelectSchema(users);\n\n// Example: validate an insert object\nconst input = { name: 'Alice', age: 30 };\nconst result = insertUserSchema.safeParse(input);\nif (result.success) {\n  console.log('Valid data:', result.data);\n} else {\n  console.error('Validation error:', result.error.issues);\n}\n\n// Custom validation: add refinements\nconst customSchema = createInsertSchema(users, {\n  name: z.string().min(2, 'Name must be at least 2 characters'),\n});\n\n// Custom validation: add refinements with coerce\nconst schemaWithCoerce = createInsertSchema(users, {\n  age: z.coerce.number().int().positive(),\n});","lang":"typescript","description":"Demonstrates creating insert and select Zod schemas from Drizzle SQLite table definition, then validates data with safeParse. Also shows custom field validations and coercion."},"warnings":[{"fix":"Use import syntax or set package.json \"type\": \"module\". Alternatively, use dynamic import: const { createInsertSchema } = await import('drizzle-zod');","message":"Package was ESM-only since version 0.8.0. CommonJS require() will throw.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Use createUpdateSchema from drizzle-zod directly; avoid custom implementations.","message":"createUpdateSchema was added in 0.7.0, but previous versions used a different pattern; ensure you use correct version.","severity":"deprecated","affected_versions":">=0.7.0"},{"fix":"Use the second argument to override field types: createInsertSchema(table, { field: z.string().optional() })","message":"createInsertSchema generates a schema that requires all fields that are not nullable or have defaults. This may be stricter than your database constraints.","severity":"gotcha","affected_versions":"all"},{"fix":"Check generated schema and apply overrides for those fields using the second parameter.","message":"When using with PostgreSQL, types like jsonb, array, etc. may produce complex Zod schemas that need manual adjustment.","severity":"gotcha","affected_versions":"all"},{"fix":"Use z.infer to extract the type. Example: type InsertUser = z.infer<typeof insertUserSchema>;","message":"TypeScript: You might need to use `z.infer<typeof insertUserSchema>` to get the type of the validated output.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"search_vec":"'0.36.0':78 '0.8.3':16 '3.25.0':73 '4.0.0':74 'addit':92 'allow':31 'alongsid':18 'automat':48 'cadenc':80 'consist':46 'coupl':63 'current':13 'custom':58 'databas':40 'defin':34 'definit':12 'depend':71 'develop':32 'differenti':47 'drizzl':2,9,19,27,65,76,84,102 'drizzle-orm':26,75 'drizzle-zod':1 'duplic':43 'ensur':45 'featur':91 'filter':59 'fix':96 'follow':83 'generat':4,49 'integr':24 'javascript':97 'minor':88 'mirror':38 'mutat':61 'mysql':105 'orm':10,20,28,66,77,85,103 'patch':94 'peer':70 'pg':104 'proper':54 'provid':22 'reduc':42 'releas':17,79 'schema':7,36,41,52,69,101 'seamless':23 'stabl':14 'support':56 'tabl':11,68 'tend':81 'tight':62 'type':55 'typescript':106 'updat':21,86 'valid':6,99,100 'version':15,89 'zod':3,5,30,35,51,72,98","created_at":"2026-06-04T18:49:35.880956+00:00","updated_at":"2026-06-04T18:49:35.880956+00:00","problems":[{"fix":"Change to import statement: import { createInsertSchema } from 'drizzle-zod'; or use dynamic import in CJS.","cause":"Package is ESM-only, but you are using CommonJS require().","error":"TypeError: drizzle_zod.createInsertSchema is not a function"},{"fix":"Run 'npm install drizzle-zod' and ensure it's in dependencies. Also install peer deps: 'npm install zod drizzle-orm'.","cause":"Package is not installed or NPM resolution issue.","error":"Cannot find module 'drizzle-zod' or its corresponding type declarations."},{"fix":"Override the field schema: createInsertSchema(table, { optionalField: z.string().optional() })","cause":"createInsertSchema marks non-nullable fields as required. If a field has a default in DB but is not marked nullable, Zod expects it on insert.","error":"Type 'undefined' is not assignable to type 'string' (or similar Zod validation error)"},{"fix":"Use z.coerce.number() on the field: createInsertSchema(table, { age: z.coerce.number() })","cause":"Drizzle schema may define field as integer, but input from form is string. Zod schema expects number.","error":"ZodError: Expected number, received string (for numeric fields)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/drizzle-team/drizzle-orm#readme","github":"https://github.com/drizzle-team/drizzle-orm","docs":null,"changelog":null,"pypi":null,"npm":"drizzle-zod","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","testing"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}