{"id":43600,"library":"pg-typegen","title":"pg-typegen","description":"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.","status":"active","version":"3.9.1","language":"javascript","source_language":"en","source_url":"https://github.com/aldis-ameriks/pg-typegen","tags":["javascript","typescript","types","database","postgres","schema","codegen","typegen"],"install":[{"cmd":"npm install pg-typegen","lang":"bash","label":"npm"},{"cmd":"yarn add pg-typegen","lang":"bash","label":"yarn"},{"cmd":"pnpm add pg-typegen","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"CLI argument parsing","package":"commander","optional":false},{"reason":"PostgreSQL client for connection and schema introspection","package":"pg","optional":false}],"imports":[{"note":"Connection string must include credentials. Use npx or install globally.","wrong":"npx pg-typegen postgres://localhost:5432/db","symbol":"pg-typegen CLI","correct":"npx pg-typegen postgres://user:pass@localhost:5432/db"},{"note":"This package is a CLI tool, not a library. No programmatic API is exported. Use npx or install globally and run from command line.","symbol":"Unknown import usage"},{"note":"Generated file will have named exports (interface and enum). Use named imports based on table/type names.","wrong":"import UserEntity from './entities'","symbol":"Generated types","correct":"import { UserEntity, UserState } from './entities'"}],"quickstart":{"code":"// Generate types from Postgres database\nnpx pg-typegen -o ./entities.ts postgres://username:password@localhost:5432/database","lang":"typescript","description":"Generates TypeScript type definitions from a Postgres database schema, outputting to entities.ts."},"warnings":[{"fix":"Ensure connection string includes username and password, e.g., postgres://admin:secret@localhost:5432/mydb","message":"Connection string must contain credentials; otherwise it may hang or fail. Use postgres://user:password@host:port/db format.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use --bigint flag to treat int8 as bigint (JavaScript BigInt) instead of string.","message":"pg-typegen does not handle bigint types by default; int8 columns map to string instead of number.","severity":"gotcha","affected_versions":"<3.0.0"},{"fix":"Add --optionals flag to get optional fields instead of nullable union types.","message":"Generated types for nullable columns include '| null' by default. Use --optionals flag to change to optional '?'.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add --type flag if you prefer type aliases over interfaces.","message":"Use of interfaces vs types: default generates interfaces. Use --type flag to generate type aliases.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'activ':14 'bigint':66 'codegen':80 'column':30 'comment':43 'configur':37 'connect':18,25 'custom':39 'databas':11,77 'date':67 'definit':7 'depend':73 'differenti':52 'direct':19 'driver':63 'enum':31,69 'generat':4 'handl':70 'insert':41 'instanc':23 'interfaces/types':48 'introspect':28 'javascript':74 'javascript/typescript':58 'key':51 'maintain':15 'map':53 'match':60 'materi':34 'multipl':45 'nativ':57 'option':50 'orm':72 'output':46,64 'pg':2,62 'pg-typegen':1 'postgr':10,22,54,78 'releas':17 'schema':12,40,79 'semicolon':49 'string':26 'style':47 'suffix':38 'support':36 'tabl':29 'type':6,42,55,59,76 'typegen':3,81 'typescript':5,75 'v3.9.1':13 'via':24 'view':32,35 'week':16","created_at":"2026-06-05T17:00:34.629539+00:00","updated_at":"2026-06-05T17:00:34.629539+00:00","problems":[{"fix":"Verify PostgreSQL is running and accessible. Check host, port, and firewall settings.","cause":"PostgreSQL server not running or connection string uses wrong host/port.","error":"Error: connect ECONNREFUSED ::1:5432"},{"fix":"Update connection string with correct credentials. For local dev, consider using peer authentication.","cause":"Invalid username or password in connection string.","error":"error: password authentication failed for user \"...\""},{"fix":"Run: npm install pg --save-dev","cause":"pg-typegen requires 'pg' as a peer dependency; likely missing.","error":"Error: Cannot find module 'pg'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/aldis-ameriks/pg-typegen#readme","github":"https://github.com/aldis-ameriks/pg-typegen","docs":null,"changelog":null,"pypi":null,"npm":"pg-typegen","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}