squirrel
Values
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:
squirrelfirst looks for all directories calledsqlunder thesrcdirectory of your Gleam project, and reads all the*.sqlfiles in there (in glob termssrc/**/sql/*.sql).- Each
*.sqlfile must contain a single query as it is turned into a Gleam function with the same name. - All functions coming from the same
sqldirectory will be grouped under a Gleam file calledsql.gleamat the same level: given asrc/$PATH/sqldirectory, you’ll end up with a generatedsrc/$PATH/sql.gleamfile.
⚠️ In order to generate type safe code,
squirrelhas to connect to your Postgres database. To know what host, user, etc. values to use when connecting, it will read theDATABASE_URLenv variable that has to be a valid connection string with the following format:postgres://user:password@host:port/database?connect_timeout=secondsIf a
DATABASE_URLvariable is not set, Squirrel will instead read your Postgres env variables and use the following defaults if one is not set:
PGHOST:"localhost"PGPORT:5432PGUSER:"postgres"PGDATABASE: the name of your Gleam projectPGPASSWORD:""PGCONNECT_TIMEOUT:5seconds
⚠️ The generated code relies on the
pogpackage to work, so make sure to add that dependency to your project.