Carpathia — generate code from PostgreSQL schemas with your own Tera templates (0.3.0 on crates.io)

carpathia — generate code from PostgreSQL schemas with your own Tera templates

carpathia — generate code from PostgreSQL schemas with your own Tera templates (0.3.0 on crates.io)

Hi everyone!

I'd like to introduce carpathia, a Rust toolkit that generates code from your PostgreSQL schema using templates you write. It's now on crates.io.

The idea: every project with a database ends up hand-writing the same boilerplate — structs mirroring tables, CRUD methods mirroring constraints, all of it re-touched by hand on every schema change. carpathia introspects your schema, turns it into a canonical model (the Abstract Database Representation), and renders your Tera templates against it. Any output, any language: Rust structs with sqlx, TypeScript types, SQL, docs — your call.

To be clear: carpathia is not an ORM and never will be. There's no runtime and no query DSL — the output is plain, ordinary code, and you decide exactly what it looks like.

A few things I care about:

  • Deterministic output — everything is ordered, so generated code checks into git with clean diffs.
  • Delta-aware caching — only objects whose schema or template changed get re-rendered; orphaned outputs are cleaned up.
  • A stable template contract — the data model your templates receive lives in its own crate (carpathia-adr) with its own versioning, independent of the engine.
  • A bundled template pack — unpack a ready-made sqlx-based Rust data-access library and edit from there instead of starting from scratch.

Getting started is two commands: install with cargo install carpathia, unpack the example templates, point it at your database, and generate.

It's functional but in beta — tested against PostgreSQL 13–18, with MySQL and SQLite planned. I'd love feedback, especially from anyone writing their own templates: what's missing from the schema model? What would you want to generate?

Thanks for reading — and happy to answer questions!