{"_id":"@calasanmarko/drizzle-zod","name":"@calasanmarko/drizzle-zod","dist-tags":{"latest":"0.5.1"},"versions":{"0.5.1":{"name":"@calasanmarko/drizzle-zod","version":"0.5.1","description":"Generate Zod schemas from Drizzle ORM schemas","type":"module","scripts":{"build":"tsx scripts/build.ts","b":"pnpm build","test:types":"cd tests && tsc","pack":"(cd dist && npm pack --pack-destination ..) && rm -f package.tgz && mv *.tgz package.tgz","publish":"npm publish package.tgz","test":"NODE_OPTIONS='--loader=tsx --no-warnings' ava"},"exports":{".":{"import":{"types":"./index.d.mts","default":"./index.mjs"},"require":{"types":"./index.d.cjs","default":"./index.cjs"},"types":"./index.d.ts","default":"./index.mjs"}},"main":"./index.cjs","module":"./index.mjs","types":"./index.d.ts","repository":{"type":"git","url":"git+https://github.com/drizzle-team/drizzle-orm.git"},"ava":{"files":["tests/**/*.test.ts","!tests/bun/**/*"],"extensions":{"ts":"module"},"nodeArguments":["--loader=tsx"]},"keywords":["zod","validate","validation","schema","drizzle","orm","pg","mysql","postgresql","postgres","sqlite","database","sql","typescript","ts"],"author":{"name":"Drizzle Team"},"license":"Apache-2.0","peerDependencies":{"drizzle-orm":">=0.23.13","zod":"*"},"devDependencies":{"@rollup/plugin-terser":"^0.4.1","@rollup/plugin-typescript":"^11.1.0","@types/node":"^18.15.10","ava":"^5.1.0","cpy":"^10.1.0","drizzle-orm":"link:../drizzle-orm/dist","rimraf":"^5.0.0","rollup":"^3.20.7","tsx":"^3.12.2","zod":"^3.20.2","zx":"^7.2.2"},"_id":"@calasanmarko/drizzle-zod@0.5.1","dist":{"shasum":"686ce091f70c82c63d7cd0855a3cbb39dcac4818","integrity":"sha512-ZbaaPRKvp8BpCswxGOO4u/PxtXOy+To3nrKLCoDgZ76a4at/OWFdhm9SJKsbiA5J0g3PnvxnXlDM+dgHEke77g==","tarball":"https://registry.npmjs.org/@calasanmarko/drizzle-zod/-/drizzle-zod-0.5.1.tgz","fileCount":9,"unpackedSize":25333,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDj/G9K7uhbKB4PAwkBpr+prCbRXuLEbQCjHm6wHzqVKAIhAINYavQaoUUwF4un/PbkEP38o0IxJ9cQXyOLm3AsihFa"}]},"_npmUser":{"name":"calasanmarko","email":"calasanmarko@hotmail.com"},"directories":{},"maintainers":[{"name":"calasanmarko","email":"calasanmarko@hotmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/drizzle-zod_0.5.1_1713219307226_0.7613188088221472"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-15T22:15:07.135Z","0.5.1":"2024-04-15T22:15:07.372Z","modified":"2024-04-15T22:15:07.673Z"},"maintainers":[{"name":"calasanmarko","email":"calasanmarko@hotmail.com"}],"description":"Generate Zod schemas from Drizzle ORM schemas","keywords":["zod","validate","validation","schema","drizzle","orm","pg","mysql","postgresql","postgres","sqlite","database","sql","typescript","ts"],"repository":{"type":"git","url":"git+https://github.com/drizzle-team/drizzle-orm.git"},"author":{"name":"Drizzle Team"},"license":"Apache-2.0","readme":"<div align='center'>\n<h1>drizzle-zod <a href=''><img alt='npm' src='https://img.shields.io/npm/v/drizzle-zod?label='></a></h1>\n<img alt='npm' src='https://img.shields.io/npm/dm/drizzle-zod'>\n<img alt='npm bundle size' src='https://img.shields.io/bundlephobia/min/drizzle-zod'>\n<a href='https://discord.gg/yfjTbVXMW4'><img alt='Discord' src='https://img.shields.io/discord/1043890932593987624'></a>\n<img alt='License' src='https://img.shields.io/npm/l/drizzle-zod'>\n<h6><i>If you know SQL, you know Drizzle ORM</i></h6>\n<hr />\n</div>\n\n`drizzle-zod` is a plugin for [Drizzle ORM](https://github.com/drizzle-team/drizzle-orm) that allows you to generate [Zod](https://zod.dev/) schemas from Drizzle ORM schemas.\n\n| Database   | Insert schema | Select schema |\n|:-----------|:-------------:|:-------------:|\n| PostgreSQL |       ✅       |       ✅       |\n| MySQL      |       ✅       |       ✅       |\n| SQLite     |       ✅       |       ✅       |\n\n# Usage\n\n```ts\nimport { pgEnum, pgTable, serial, text, timestamp } from 'drizzle-orm/pg-core';\nimport { createInsertSchema, createSelectSchema } from 'drizzle-zod';\nimport { z } from 'zod';\n\nconst users = pgTable('users', {\n  id: serial('id').primaryKey(),\n  name: text('name').notNull(),\n  email: text('email').notNull(),\n  role: text('role', { enum: ['admin', 'user'] }).notNull(),\n  createdAt: timestamp('created_at').notNull().defaultNow(),\n});\n\n// Schema for inserting a user - can be used to validate API requests\nconst insertUserSchema = createInsertSchema(users);\n\n// Schema for selecting a user - can be used to validate API responses\nconst selectUserSchema = createSelectSchema(users);\n\n// Overriding the fields\nconst insertUserSchema = createInsertSchema(users, {\n  role: z.string(),\n});\n\n// Refining the fields - useful if you want to change the fields before they become nullable/optional in the final schema\nconst insertUserSchema = createInsertSchema(users, {\n  id: (schema) => schema.id.positive(),\n  email: (schema) => schema.email.email(),\n  role: z.string(),\n});\n\n// Usage\n\nconst user = insertUserSchema.parse({\n  name: 'John Doe',\n  email: 'johndoe@test.com',\n  role: 'admin',\n});\n\n// Zod schema type is also inferred from the table schema, so you have full type safety\nconst requestSchema = insertUserSchema.pick({ name: true, email: true });\n```\n","readmeFilename":"README.md"}