Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pg2struct

Introspect a Postgres schema and generate typed structs/classes in the language of your choice.

Install

npm install -g pg2struct
# or run without installing:
npx pg2struct --help

Usage

pg2struct --conn <connection-string> --lang <language> [options]
Flag Short Description
--conn -c Postgres connection string. Falls back to $DATABASE_URL if omitted.
--schema -s Schema to introspect. Default: public.
--table -t Restrict to specific table(s). Repeatable (-t a -t b) or comma-separated (-t a,b).
--lang -l Target language for generated output (required). See below for supported values.
--out -o Output file path. Default: stdout.
--help -h Show usage.

Each table becomes a named top-level type in the output (e.g. table users → type Users). Nullable columns are generated as optional/nullable fields in the target language.

Examples

pg2struct -c postgres://localhost/mydb -l go
pg2struct -c postgres://localhost/mydb -l typescript -o schema.ts
pg2struct -c postgres://localhost/mydb -l python -s app -t users -t orders
DATABASE_URL=postgres://localhost/mydb pg2struct -l rust -o schema.rs

Supported languages

Any language supported by quicktype-core, including go, python, typescript, java, csharp, rust, kotlin, swift, ruby, dart, php, crystal, elm, haskell, objective-c, cplusplus, pike, scala3, and more. Run pg2struct with a missing or invalid --lang to print the full current list.

Development

bun install
bun bin/pg2struct.js --help

License

MIT — see LICENSE.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages