Convert PostgreSQL schemas into TypeScript interfaces. v0.5.0 is the latest stable release. This package provides a CLI and programmatic API to generate TypeScript type definitions from Postgres database schemas. It focuses on simplicity with no configuration required, supporting both full schema inference and per-table generation. Unlike alternatives like schemats, it is Postgres-only, uses inline enums, and avoids namespaces. The generation respects PostgreSQL defaults such as nullable columns (producing union with null) and timestamp mapping to Date. No recent updates since 2022.
npm install postgres-schema-tsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates both CLI usage and programmatic import to generate TypeScript interfaces from a Postgres schema connection string.
Use postgresql://user:pass@host/db instead of postgres://user:pass@host/db
Add '?currentSchema=public' (or your schema) to the connection string
npx postgres-schema-ts <args> > schema.ts
Use import syntax or set 'type': 'module' in package.json or use dynamic import.
If you prefer undefined, manually adjust generated types.
Consider alternatives like schemats or pg-to-ts if newer features are needed.
Ensure PostgreSQL is running on the specified port (default 5432) and correct connection string.
Use explicit IP 127.0.0.1 or host.docker.internal if in Docker.
Add 'type': 'module' to package.json, or use .mjs extension, or compile with TypeScript.
Manually adjust the generated interface or file an issue on GitHub.