Elixir-native SQL query code generation for Mix projects.
Squirrelix discovers .sql files under conventional Elixir source roots
(lib/, test/, dev/), then generates sibling sql.ex modules with
@spec-annotated functions that execute through Postgrex.
Supported public API
Pre-1.0, the supported programmatic surface is intentionally small:
generate/3/check/3— primary entry points- Mix tasks
mix squirrelix.genandmix squirrelix.check - Return summaries
Squirrelix.CodegenSummary/Squirrelix.CodegenCheckSummary - Documented
Squirrelix.Error.*structs (andSquirrelix.Error.format/1) Squirrelix.Postgres.inferrer/1andSquirrelix.Inference.Inferrer(plusSquirrelix.Queryas the Inferrer callback argument)
Other modules under Squirrelix.* are internal (@moduledoc false) and
may change without notice. See Configuration
for the full inventory.
Guides
- Getting Started — installation, layout, first query
- Writing Queries — one query per file, comments, naming
- Types — Postgres to Elixir type mapping
- Configuration — inference, metadata, connection, CI
See also README.md for a full overview.
Query sources
Generation and checking accept a query source in one of two forms:
- A metadata map — keys are query file paths, values are keyword lists with
:paramsand:returns. Load fromsquirr_elix.exsor pass a map togenerate/3andcheck/3. An inferrer — a
(query -> {:ok, keyword()} | {:error, struct()})function or a module implementingSquirrelix.Inference.Inferrer. The Mix task uses this mode with--inferto ask Postgres for column and parameter types.
Generated code uses stdlib types in @spec output: String.t() for Postgres
enums, term() for JSON/JSONB columns, map() with required/1 for row
shapes, and plain maps at runtime rather than Gleam records or custom enum ADTs.
Summary
Functions
Checks that generated query modules are current without writing files.
Generates query modules for SQL files discovered under a Mix project root.
Types
Functions
@spec check(Path.t(), query_source(), keyword()) :: Squirrelix.CodegenCheckSummary.t()
Checks that generated query modules are current without writing files.
Accepts the same query_source and options as generate/3.
Fails globally when any directory has query errors or drift — the summary
status is :error and every failing directory is included in :errors.
Returns a Squirrelix.CodegenCheckSummary struct.
@spec generate(Path.t(), query_source(), keyword()) :: Squirrelix.CodegenSummary.t()
Generates query modules for SQL files discovered under a Mix project root.
Generation is project-wide atomic: if any sql/ directory has query errors
(invalid names, missing metadata, inference failures, …), nothing is written —
including directories that would otherwise succeed. Fix every error, then re-run.
Options
:version(required) — generator version string written into file headers:postgrex— module passed to generated code (defaults toPostgrex)
Returns a Squirrelix.CodegenSummary struct summarizing writes and errors.