A CLI tool and Node module (v1.0.24) that introspects PostgreSQL database schemas and generates Zod v4 type schemas for each table and view. It connects directly to a Postgres instance using pg-structure, outputs TypeScript files, and supports customizable configuration via JSON files. Unlike manual schema writing or ORM-based generators, it provides a focused, zero-runtime-dependency pipeline for keeping Zod definitions in sync with database schemas. Release cadence is irregular; last update was in 2025.
npm install pg-tables-to-zodNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Connects to a Postgres database and generates Zod schemas for all tables in the public schema, writing them to ./schemas.
Ensure your project uses zod@^4.0.0. If using zod v3, the generated schemas will cause runtime errors.
Upgrade to zod v4 or use a different tool (e.g., schemats) for Zod v3 compatibility.
Always use await convert(configuration) or .then().
Install the package with npm install pg-tables-to-zod (types are bundled). Ensure tsconfig.json has `moduleResolution: 'node'` (or 'node16' for ESM).
Run npm install pg-tables-to-zod. Verify the package is in node_modules.
Upgrade to zod v4: npm install zod@latest