glimr/db/gen/generator

Model Code Generator

Every time you add a column to a table, you’d normally need to update the type definition, the row decoder, the JSON encoder, the JSON decoder, and every query function that touches that table. This module does all of that automatically — it reads the parsed schema and SQL query files and spits out complete, ready-to-use Gleam modules with types, decoders, encoders, and query wrappers.

Values

pub fn generate(
  model_name: String,
  table: schema_parser.Table,
  queries: List(#(String, String, parser.ParsedQuery)),
  schema_content: String,
) -> String

One call produces an entire Gleam module — header, imports, model type, row decoder, JSON encoder/decoder, and all query functions. Callers don’t need to worry about ordering or which pieces depend on which; this function handles the assembly so the build step is just “parse schema, parse queries, generate.”

Search Document