squirrel
Functions
pub fn main() -> Nil
🐿️ Performs code generation for your Gleam project.
squirrel
is not configurable and will discover the queries to generate
code for by relying on a conventional project’s structure:
squirrel
first looks for all directories calledsql
under thesrc
directory of your Gleam project, and reads all the*.sql
files in there (in glob termssrc/**/sql/*.sql
).- Each
*.sql
file must contain a single query as it is turned into a Gleam function with the same name. - All functions coming from the same
sql
directory will be grouped under a Gleam file calledsql.gleam
at the same level: given asrc/$PATH/sql
directory, you’ll end up with a generatedsrc/$PATH/sql.gleam
file.
⚠️ In order to generate type safe code,
squirrel
has to connect to your Postgres database. To know what host, user, etc. values to use when connecting, it will read your Postgres env variables.If a variable is not set it will go with the following defaults:
PGHOST
:"localhost"
PGPORT
:5432
PGUSER
:"root"
PGDATABASE
: the name of your Gleam projectPGPASSWORD
:""
⚠️ The generated code relies on the
gleam_pgo
anddecode
packages to work, so make sure to add those as dependencies to your project.