Generate TypeScript type definitions from a Postgres database schema. v3.9.1 — actively maintained, weekly releases. Connects directly to a Postgres instance via connection string and introspects tables, columns, enums, views, and materialized views. Supports configurable suffixes, custom schemas, insert types, comments, and multiple output styles (interfaces/types, semicolons, optionals). Key differentiator: maps Postgres types to native JavaScript/TypeScript types matching the pg driver output, with bigint, date, and enum handling. No ORM dependency.
npm install pg-typegenNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Generates TypeScript type definitions from a Postgres database schema, outputting to entities.ts.
Ensure connection string includes username and password, e.g., postgres://admin:secret@localhost:5432/mydb
Use --bigint flag to treat int8 as bigint (JavaScript BigInt) instead of string.
Add --optionals flag to get optional fields instead of nullable union types.
Add --type flag if you prefer type aliases over interfaces.
Verify PostgreSQL is running and accessible. Check host, port, and firewall settings.
Update connection string with correct credentials. For local dev, consider using peer authentication.
Run: npm install pg --save-dev