⚡ Zig Guide LiveUnofficialbut fully verified
✓ Zig 0.18.0-dev.624+b7f2c6d8fWhat's newOn an older Zig?Blograylib-zig

An Ecto-Style ORM

This project is longer than a recipe: one library, designed in public, with one decision in each chapter. The library is a database layer in the shape of Ecto. That design is a good stress test of comptime. The schema is a type, and the compiler checks the query builder against that type before the program runs. Migrations are data. The driver is behind one seam, so the same code runs on SQLite or PostgreSQL.

  1. The schema is a type. At compile time, the library derives every other part from the schema, and declares nothing twice.
  2. A query builder that checks field names during compilation changes a class of runtime SQL errors into build errors.
  3. errdefer makes a transaction correct on the error paths that you did not think about.
  4. If you put the driver behind one seam, the same query code runs on two databases. If the driver code is in many places, the code runs only on the database that you wrote first.

9 chapters.