gieter 0.2.0

Command-line code generator that turns database schemas into typed source code
gieter-0.2.0 is not a library.

gieter (Dutch for watering can) introspects a live database and emits typed source code from it. It reads your schema, tables, columns, enums, keys, etc. and turns it into a neutral intermediate representation, then hands that to pluggable emitters to generate code in the language of your choice.

Today it ships a PostgreSQL source and a TypeScript emitter.

Features

  • Live introspection of PostgreSQL schemas (tables, columns, enums, primary & foreign keys, comments).
  • Typed TypeScript output with configurable type/interface, enum, casing, and null styles.
  • Branded ID types; nominal types for primary/foreign keys so a UserId can't be passed where a PostId belongs.
  • Scalar type overrides with automatic import hoisting.
  • Flexible file layout; split kinds across files or emit everything into one.
  • Extensible by design; sources and emitters are just crates implementing a gieter_core trait.

Missing features

Things that are currently not supported by gieter but are planned are:

  • Python emitter.
  • Zod emitter.
  • Rust emitter.
  • Plugin system so you can create external schema sources and emitters, then load them via config options.

Install

cargo install gieter

Or build from source:

git clone https://github.com/stevenliebregt/gieter
cd gieter
cargo install --path crates/gieter

Quick start

Create a gieter.toml:

[source]
type = "postgres"
url = "postgres://user:password@localhost:5432/db"
schemas = ["public"]

[[emitter]]
type = "typescript"
out_dir = "src/db"
output = "schema.ts"

Then run:

gieter # uses ./gieter.toml
gieter --config path/to/gieter.toml

The database URL may be read from the environment with url = "env:DATABASE_URL". See examples/ for a fully-annotated config.

Extending gieter

Everything hangs off gieter_core, which defines the schema IR plus the Source and Emitter traits. To target a new language or database, depend on it directly:

[dependencies]
gieter_core = "0.1"

Implement Emitter (or Source), and register it with the pipeline.

License

Licensed under either of MIT or Apache-2.0 at your option.