Package Exports
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (drizzle-zod) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
drizzle-zod is a plugin for Drizzle ORM that allows you to generate Zod schemas from Drizzle ORM schemas.
| Database | Insert schema | Select schema | 
|---|---|---|
| PostgreSQL | ✅ | ⏳ | 
| MySQL | ⏳ | ⏳ | 
| SQLite | ⏳ | ⏳ | 
Usage
import { pgEnum, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';
import { z } from 'zod';
import { createInsertSchema } from 'drizzle-zod/pg';
const users = pgTable('users', {
  id: serial('id').primaryKey(),
  name: text('name').notNull(),
  email: text('email').notNull(),
  role: text<'admin' | 'user'>('role').notNull(),
  createdAt: timestamp('created_at').notNull().defaultNow(),
});
const newUserSchema = createInsertSchema(users);
// Transform keys to snake case
const newUserSchema = createInsertSchema(users, 'snake');
// Transform keys to camel case
const newUserSchema = createInsertSchema(users, 'camel');
// Override the fields
const newUserSchema = createInsertSchema(users, {
  // this is required for runtime validation of text enum types, otherwise z.string() will be used
  role: z.enum(['admin', 'user']),
});
// Refine the fields
const newUserSchema = createInsertSchema(users, (schema) => ({
  id: schema.id.positive(),
  email: schema.email.email(),
  role: z.enum(['admin', 'user']),
}));
const newUserSchema = createInsertSchema(users, 'snake', (schema) => ({
  created_at: schema.createdAt.min(new Date()),
}));
// Usage
const user = newUserSchema.parse({
  name: 'John Doe',
  email: 'johndoe@test.com',
  role: 'admin',
});
// Zod schema type is also inferred from the table schema, so you have full type safety
const requestSchema = newUserSchema.pick({ name: true, email: true });