Registry / database / database-validator-generator

database-validator-generator

JSON →
library0.0.1jsnpmunverified

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.

npm install database-validator-generator
INSTALL
IMPORT
SIG · DATABASE-VALIDATOR
D
database-validator-generator
databasejavascriptv0.0.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

usersSchema
✓ import { usersSchema } from "./schemas.mjs"
✗ const { usersSchema } = require("./schemas.mjs")
Generated file is ESM-only (.mjs). CommonJS require will fail.
schemas
✓ import { schemas } from "./schemas.mjs"
✗ import schemas from "./schemas.mjs"
Default export is not provided; must use named import.
z
✓ import { z } from "zod"
✗ import * as z from "zod"
Zod v4 supports named import for the z object; star import may cause issues with tree-shaking.

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
database-validator-generator --version
Debug
Known issues
breakingGenerated schemas target Zod v4. Using with Zod v3 will cause runtime errors.
fix
Install zod@^4.0.0: npm install zod@4
affects: >=0.0.1
gotchaThe 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).
affects: >=0.0.1
gotchaConnection string must include credentials. SSL may be required for hosted databases.
fix
Use --connection with sslmode=require or set DATABASE_URL accordingly.
affects: >=0.0.1
deprecatedN/A for version 0.0.1
Errors
Common errors & fixes
Error: Cannot find module 'zod'
zod is a peer dependency and must be installed explicitly.
fix
Run: npm install zod@^4.0.0
Error [ERR_REQUIRE_ESM]: require() of ES Module
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: expected 'z.object(...)' got 'z.union(...)'
Zod v4 changed some APIs; generated code uses v4 syntax.
fix
Ensure you have zod@^4.0.0 installed.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies
zodrequiredPeer dependency required by generated schemas; must be installed separately.
Agent activity
8 hits · last 30 days
node
8
Resources
database-validator-generator — npm install database-validator-generator · libregistry