database-validator-generator

raw JSON →
0.0.1 verified Sat May 09 auth: no javascript

CLI tool that generates Zod v4 schemas and JSDoc typedefs from PostgreSQL database metadata. Version 0.0.1 is the initial release. It connects to a Postgres instance, inspects tables, and outputs an ESM module with Zod schemas for runtime validation. Unlike ORM-based solutions or generic schema generators, it targets Zod v4 specifically and is intentionally minimal: no migrations, no query building, no abstraction layer. Relies on a peer dependency of zod@^4.0.0. Development is active, with frequent updates expected.

error Error: Cannot find module 'zod'
cause zod is a peer dependency and must be installed explicitly.
fix
Run: npm install zod@^4.0.0
error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Generated file is ESM and cannot be used with require().
fix
Use dynamic import: import('./schemas.mjs') or set type: 'module' in package.json.
error error: expected 'z.object(...)' got 'z.union(...)'
cause Zod v4 changed some APIs; generated code uses v4 syntax.
fix
Ensure you have zod@^4.0.0 installed.
breaking Generated schemas target Zod v4. Using with Zod v3 will cause runtime errors.
fix Install zod@^4.0.0: npm install zod@4
gotcha The generated file is ESM (.mjs) and uses top-level await. It cannot be required via CommonJS.
fix Use import() or convert your project to ESM (type: "module" in package.json).
gotcha Connection string must include credentials. SSL may be required for hosted databases.
fix Use --connection with sslmode=require or set DATABASE_URL accordingly.
deprecated N/A for version 0.0.1
npm install database-validator-generator
yarn add database-validator-generator
pnpm add database-validator-generator

Installs the cli and zod, generates schemas from a postgres database, then shows the output file.

npm install --save-dev database-validator-generator
npm install zod
DATABASE_URL="postgres://user:password@localhost:5432/app" npx database-validator-generator generate
cat schemas.mjs