⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.17.0-dev.1503+1f1bee62eOn an older Zig?

An Ecto-Style ORM

Longer than a recipe: one library, designed in the open, one decision per chapter. A database layer in the shape of Ecto, which is a good stress test of comptime because the schema is a type, the query builder is checked against that type before the program runs, migrations are data, and the driver sits behind one seam so the same code runs on SQLite or PostgreSQL.

  1. The schema is a type. Every other part of the library is derived from it at compile time rather than declared twice.
  2. A query builder that checks field names during compilation turns a class of runtime SQL errors into build errors.
  3. errdefer is what makes a transaction correct on the error paths you did not think about, which are the ones that matter.
  4. Put the driver behind one seam and the same query code runs on two databases. Scatter it and it runs on whichever you wrote first.

9 chapters.