dream_sql_generator

Values

pub fn main() -> Nil

🐿️ Performs code generation for your Gleam project.

squirrel will discover the queries to generate code for by relying on a conventional project’s structure:

  • squirrel first looks for all directories called sql under the src directory of your Gleam project, and reads all the *.sql files in there (in glob terms src/**/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 called sql.gleam at the same level: given a src/$PATH/sql directory, you’ll end up with a generated src/$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 the DATABASE_URL env variable that has to be a valid connection string with the following format:

postgres://user:password@host:port/database?connect_timeout=seconds

If a DATABASE_URL variable is not set, Squirrel will instead read your Postgres env variables and use the following defaults if one is not set:

  • PGHOST: "localhost"
  • PGPORT: 5432
  • PGUSER: "postgres"
  • PGDATABASE: the name of your Gleam project
  • PGPASSWORD: ""
  • PGCONNECT_TIMEOUT: 5 seconds

⚠️ The generated code relies on the pog package to work, so make sure to add that dependency to your project. To use another module with the same API, such as dream_postgres_client, set it in the [tools.dream_sql_generator] table of your gleam.toml:

[tools.dream_sql_generator]
client_module = "dream_postgres_client"
✨ Search Document