npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@lucaconlaq/drizzle-zod-to-code

v0.2.3

Published

Generate Zod schemas (as code) from Drizzle ORM schemas

Downloads

346

Readme

Drizzle Zod To Code

Logo

Generate JavaScript/TypeScript code for Drizzle Zod schemas

npm biome vitest


✨ Why?

This library was born in response to a need discussed in drizzle-orm issue #941: generating static validation schemas (i.e. Zod) from Drizzle ORM models without bundling Drizzle into the client.

  • 🔄 It extracts schema logic from Drizzle models and outputs Zod code using zod-to-code.
  • 🔐 This keeps your frontend secure by removing ORM logic from client builds.
  • 🧩 Great for full-stack apps that share validation between backend and frontend.

⚠️ Why dynamic Zod schemas are not always ideal

When sharing validation between server and client, using dynamic (runtime) Zod schemas, generated with drizzle-zod can lead to several issues:

  • 🔓 Risk of code leakage – Dynamic schemas created with createInsertSchema or similar rely on Drizzle's runtime logic. When used in frontend code, this can unintentionally bundle server-only logic into the client, potentially exposing sensitive code or internal database structures.
  • 🐘 Large bundle size – Including Drizzle ORM in the client pulls in unnecessary dependencies, increasing bundle size and hurting performance.

Static schema generation avoids all of these issues.


🚀 Installation

npm i @lucaconlaq/drizzle-zod-to-code

📦 Usage

npx drizzle-zod-to-code generate --out ../schemas/src/

Options

  • --config <path> - Path to drizzle.config.ts (default: "drizzle.config.ts")
  • --out <path> - Path for generated Zod schemas (default: "src/schemas")
  • --ts-config <path> - Path to tsconfig.json (default: "tsconfig.json")
  • -h, --help - Display help for command

Add to package.json

You can add it to your package.json scripts:

{
  ...
  "scripts": {
    ...
    "drizzle:generate": "drizzle-kit generate",
    "drizzle:migrate": "drizzle-kit migrate",
    "drizzle:push": "drizzle-kit push",
    "drizzle:pull": "drizzle-kit pull",
    "drizzle:studio": "drizzle-kit studio",
    "drizzle:generate:zod": "drizzle-zod-to-code generate --out ../schemas/src/"
  }
}

Then you can run:

npm run drizzle:generate:zod

🚨 Limitations

This is an initial release focused on the most common use cases. While it provides a solid foundation for generating static Zod schemas from Drizzle models, it does not cover all the use-cases that drizzle-zod support. If you find a bug, please consider contributing.

✅ Test Coverage

The test suite in test/drizzle/ mirrors the test suite of drizzle-zod. Here's a summary of the current test coverage across different databases:

| DB | Files | Total Tests | Skipped | |------------|-----------------------------------------------------------------------|-------------|---------| | 🐬 MySQL | mysqlTable, mysqlView, mysqlTypes, mysqlSchemaValidation | 21 | 13 | | 🐘 Postgres | pgTable, pgView, pgTypes, pgSchemaValidation | 22 | 8 | | 🪨 SQLite | sqliteTable, sqliteView, sqliteTypes, sqliteSchemaValidation | 18 | 13 |