glimr/db/gen/generator
Code Generator
Generates typed Gleam repository modules from parsed schema definitions and SQL query files. Produces complete, formatted Gleam code including:
- Model type definitions matching the schema
- Decoder functions for database rows
- Query functions for each SQL file (returning Results)
- Row types for queries with custom SELECT columns
Values
pub fn generate(
model_name: String,
table: schema_parser.Table,
queries: List(#(String, String, parser.ParsedQuery)),
driver_type: String,
) -> String
Generates a complete Gleam repository module for a model. Combines the header, imports, model type, decoder, and all query functions into a single module string.
The driver_type parameter should be “sqlite” or “postgres” to generate driver-specific imports and function calls.