Packages

The SQL layer for lode: a parameterized SQL renderer, the PostgreSQL adapter (via pog), hand-authored migrations with a CLI, schema-first codegen, and a spec-vs-database drift checker.

Current section

Files

Jump to
lode_sql README.md
Raw

README.md

# lode_sql
The SQL layer for [lode](https://github.com/blakedietz/lode): the
dialect-parameterized SQL renderer, the PostgreSQL adapter (via
[`pog`](https://hexdocs.pm/pog)), the SQLite adapter (via
[`sqlight`](https://hexdocs.pm/sqlight)), and migrations. Mirrors Elixir's
`ecto_sql` package. Depends on the database-agnostic `lode` core.
`lode` is resolved from [Hex](https://hex.pm/packages/lode). The runnable
examples still build against this checkout and a sibling `lode` checkout by
path, so to work on the examples clone the two repos side by side.
## Modules
- `lode/query/sql` — render a `Query` (and INSERT/UPDATE/DELETE) to
parameterized SQL in a dialect (`sql.postgres()` / `sql.sqlite()`).
- `lode/adapters/postgres` — a `lode` adapter built on `pog`.
- `lode/adapters/sqlite` — a `lode` adapter built on `sqlight` (in-memory or
file databases; no server).
- `lode/migration`, `lode/migration/ddl` — the typed, auto-reversible migration
DSL.
- `lode/migrator``migrate` / `rollback` / `status` over a `schema_migrations`
table — the DDL dialect is inferred from the adapter's engine.
## Tests
The Postgres and migration tests need a Postgres on `localhost:5432` with a
`lode_test` database the current OS user can reach:
```sh
createdb lode_test
gleam test
```
The SQLite tests (`test/sqlite_test.gleam`) run against
`sqlight.open(":memory:")` and need no server.
## Examples
[`examples/codegen_demo`](examples/codegen_demo) is a self-contained project
showing the schema-first workflow: a hand-authored schema spec generates the
typed schema modules **offline** (`gleam run -m regenerate`, no database),
hand-written migrations drive Postgres, a drift check verifies the two agree,
and the demo uses the generated module to insert/query/preload:
```sh
cd examples/codegen_demo
docker compose up -d
gleam run
```
[`examples/lustre_form`](examples/lustre_form) is a full-stack demo: a shared
validation core (dual-target `lode`, no SQL) reused by a Lustre client and a
wisp server that persists with `lode_sql` against Postgres.