๐Ÿฟ๏ธ Type safe SQL in Gleam
0

Configure Feed

Select the types of activity you want to include in your feed.

CHANGELOG#

Unreleased#

  • Squirrel now uses a better name for the generated function connection parameter. (Giacomo Cavalieri)

4.7.0 - 2026-06-03#

  • Squirrel can now pick some better argument names based on the structure of the SQL queries in the generated code. For example:

    select squirrel.name
    from squirrel
    where squirrel_id = $1
    

    The generated function is going to have the following definition:

    pub fn select_squirrel(
      db: pog.Connection,
      squirrel_id: Int
    ) -> Result(pog.Returned(GetLoginLinkRow), pog.QueryError) {
      // ... the generated code ...
    }
    

    Notice how Squirrel could use squirrel_id as a parameter name rather than a generic arg_1 name. (Giacomo Cavalieri)

  • Squirrel no longer adds whitespaces on empty comment lines. (Giacomo Cavalieri)

  • Fixed a bug where Squirrel would not properly format generated dealing with more than a single enum. (Giacomo Cavalieri)

4.6.0 - 2025-11-15#

  • Added support for the name type, represented as a Gleam String. (Giacomo Cavalieri)

4.5.0 - 2025-10-24#

  • Squirrel will no longer perform code generation if there's any errors in the queries. Before it would still generate code for the queries with no errors. This would usually lead the codebase in a broken state until all the errors were fixed. (Giacomo Cavalieri)

  • When trying to use a timestamptz, squirrel will now show a useful hint nudging to use a timestamp instead. (Giacomo Cavalieri)

4.4.2 - 2025-10-06#

  • Fix a bug where squirrel would generate invalid code for enums with a long name. (Giacomo Cavalieri)

4.4.1 - 2025-08-25#

  • Squirrel now adds return type annotations to the generated code. (Giacomo Cavalieri)

4.4.0 - 2025-08-25#

4.3.0 - 2025-08-22#

  • Added support for the citext type. (Leah Ulmschneider)

  • Fixed a bug where Squirrel would generate code that is not formatted for queries with many arguments. (Giacomo Cavalieri)

4.2.0 - 2025-07-31#

  • Before writing the generated queries, Squirrel will make sure to not overwrite any file that was not automatically generated. In case a file with the same name already exists, Squirrel will refuse to overwrite it and prompt the used to first rename the existing file. (Giacomo Cavalieri)

  • Squirrel will now include a doc comment at the beginning of each generated module, explaining where the queries come from and what version of squirrel was used to generate the code. (Giacomo Cavalieri)

4.1.0 - 2025-07-28#

  • Squirrel will now pick files under a project's test and dev directories. (Giacomo Cavalieri)

  • Fixed a bug where Squirrel wouldn't be able to generate code for .sql files with a do block. (Giacomo Cavalieri)

  • Fixed a bug where queries would not be generated in a reproducible order, causing squirrel check to fail unexpectedly. (Giacomo Cavalieri)

4.0.1 - 2025-07-14#

  • Fixed a bug where using numeric types in a query would result in runtime decoding errors. (Giacomo Cavalieri)

4.0.0 - 2025-07-07#

3.1.0 - 2025-07-04#

  • You can now use the PGCONNECT_TIMEOUT variable to set the maximum time in seconds to wait while connecting:

    # Wait at most 5 seconds before timing out when connecting to the database.
    export PGCONNECT_TIMEOUT=5
    gleam run -m squirrel
    

    You can also change the timeout value when using a connection string, by setting the connect_timeout query parameter:

    export DATABASE_URL="postgres://user@host:5432/my_db?connect_timeout=5"
    gleam run -m squirrel
    

    (Giacomo Cavalieri)

  • Updated code for gleam_stdlib >= 0.61.0 and < 1.0.0. (Giacomo Cavalieri)

  • Updated the mug dependency to >= 3.0.0 and < 4.0.0. (Giacomo Cavalieri)

v3.0.6 - 2025-06-24#

v3.0.5 - 2025-06-22#

  • Fixed a bug where the code generated by Squirrel wouldn't be properly formatted in case of a query returned rows with many columns. (Giacomo Cavalieri)

v3.0.4 - 2025-05-19#

v3.0.3 - 2025-04-28#

  • Fixed a bug where Squirrel would not be able to generate code for queries with recursive common table expressions relying on semi joins. (Giacomo Cavalieri)

v3.0.2 - 2025-04-01#

  • Fixed a bug where Squirrel couldn't tell a Postgres server had a version below the minimum required one. (Giacomo Cavalieri)

v3.0.1 - 2025-02-16#

  • Fixed a bug where code generation would include an unused import. (Leah Ulmschneider)

  • Fixed a bug where the generated code would not be formatted properly. (Giacomo Cavalieri)

v3.0.0 - 2025-01-20#

  • Added a new command line option check, to check that the generated code is up to date with the sql queries. (Giacomo Cavalieri)

  • The exit function from the squirrel module has been removed. (Giacomo Cavalieri)

  • The CLI text displayed by Squirrel will never exceed the 80 chars line limit. (Giacomo Cavalieri)

v2.1.0 - 2024-12-22#

  • The version requirement for pog has been changed to only permit v3. (Giacomo Cavalieri)

  • The generated code no longer relies on the decode package and now uses the gleam/dynamic/decode module from the gleam_stdlib package. (Giacomo Cavalieri)

v2.0.5 - 2024-12-12#

  • Fixed a bug where queries with enum arrays would cause an error. (Leah Ulmschneider)

v2.0.4 - 2024-12-04#

  • Replace deprecated gleam/regex module with gleam/regexp. (Surya Rose)

v2.0.3 - 2024-11-28#

  • Improved error message when using a Postgres version that's too old. (Giacomo Cavalieri)

v2.0.2 - 2024-11-20#

  • Fixed a bug where certain queries using conditions on foreign key would generate code with the wrong optional types. (Giacomo Cavalieri)

  • drop is now highlighted as a keyword in sql snippets in error messages. (Giacomo Cavalieri)

v2.0.1 - 2024-11-18#

  • Fixed a bug where certain queries would generate code with the wrong optional types. (Giacomo Cavalieri)

v2.0.0 - 2024-11-11#

v1.8.1 - 2024-11-08#

  • Squirrel now errors if a query returns multiple columns with the same name instead of generating invalid Gleam code. For example:

    select
      1 as duplicate,
      2 as duplicate,
      3 as not_duplicate
    

    Results in the following error:

    Error: Duplicate names
    
        โ•ญโ”€ query.sql
        โ”‚
      1 โ”‚ select
      2 โ”‚   1 as duplicate,
      3 โ”‚   2 as duplicate,
      4 โ”‚   3 as not_duplicate
        โ”†
    
    This query returns multiple values sharing the same name: `duplicate`.
    

    (Giacomo Cavalieri)

v1.8.0 - 2024-10-25#

  • Added support for postgresql URL scheme. (Valentin Iancu)

  • Switched to decode's new zero API for generated decoders. (Giacomo Cavalieri)

  • Added support for user-defined enums. An enum like this one:

    create type squirrel_colour as enum (
      'light_brown',
      'grey',
      'red'
    )
    

    Is automatically turned into the equivalent Gleam type:

    pub type SquirrelColour {
      LightBrown
      Grey
      Red
    }
    

    (Giacomo Cavalieri)

v1.7.1 - 2024-09-22#

  • Fixed a bug where a query failing to parse would cause code generation for other queries to fail unexpectedly. (Giacomo Cavalieri)

  • Fixed a bug where a query starting with a semicolon would result in a crash instead of a proper syntax error. (Giacomo Cavalieri)

  • Fixed a bug where the generated code would have needless empty lines. (Giacomo Cavalieri)

v1.7.0 - 2024-09-09#

  • Fixed a bug where an authentication error would result in a failure with a confusing error message. (Giacomo Cavalieri)

  • Added support for the timestamp type, represented as tuples #(#(Int, Int, Int), #(Int Int Int)) with #(#(year, month, day), #(hour, minute, second)). (Tommy Heffernan)

  • Fixed a bug where the SQL query displayed in an error would be dimmed out. (Giacomo Cavalieri)

  • Added more SQL keywords to syntax highlighting in error messages. (Giacomo Cavalieri)

v1.6.1 - 2024-09-04#

  • Fixed a bug where squirrel would not properly display some error messages. (Giacomo Cavalieri)

  • Improved syntax highlighting for sql queries displayed in error messages. (Giacomo Cavalieri)

  • Added a small hint in case no query is found, suggesting the correct project structure to follow. (Giacomo Cavalieri)

v1.6.0 - 2024-09-03#

  • Added support for the date type, represented as a triple #(Int, Int, Int) with #(year, month, day). (Giovanni Paone)

v1.5.0 - 2024-08-19#

v1.4.0 - 2024-08-16#

  • Added support for the uuid type, represented as a Uuid (from the youid package). (Giacomo Cavalieri)

  • Fixed a bug where gleam run -m squirrel would return a 0 exit code even in case of errors. (Giacomo Cavalieri)

v1.3.2 - 2024-08-15#

  • Fixed a bug where the generated code would be missing a gleam/list import when dealing with Postgres arrays. (Giacomo Cavalieri)

v1.3.1 - 2024-08-15#

  • Fixed a bug where Squirrel would panic if not able to establish a TCP connection to the postgres server. Now it gracefully handles the error by showing an appropriate error message. (Giacomo Cavalieri)

v1.3.0 - 2024-08-13#

  • One can now use the DATABASE_URL env variable to specify a connection string that Squirrel will use to connect to the Postgres database. All the regular Postgres variables are still supported, but Squirrel will pick DATABASE_URL over those if it is set. (Giacomo Cavalieri)

  • Added support for the jsonb type, encoded as a Json (from the gleam_json package) and decoded as a Gleam String. (Giacomo Cavalieri)

  • Added support for the json type, encoded as Json (from the gleam_json package) and decoded as a Gleam String. (Giacomo Cavalieri)

v1.2.0 - 2024-08-12#

  • Squirrel now supports the SCRAM-SHA-256 authentication. (Giacomo Cavalieri)

  • Squirrel now uses the name of your Gleam project as the default database name to connect to. (Giacomo Cavalieri)

  • Fixed a bug where Squirrel couldn't generate code for queries that return no rows like insert into. (Giacomo Cavalieri)

  • Avoid panicking when the authenticated user doesn't have the permission to access a given table. (Giacomo Cavalieri)

v1.1.0 - 2024-08-11#

  • Squirrel now supports plaintext password authentication. (Giacomo Cavalieri)

  • Squirrel now uses "postgres" as the default user in case the PGUSER environment variable is not set. (Giacomo Cavalieri)

  • Added support for the varchar and bpchar types, mapped to Gleam Strings. (Giacomo Cavalieri)

  • Improved the error message in case Squirrel cannot connect to the Postgres server with the given database and username. Instead of a not-really-helpful Cannot receive message: Closed the error now properly explains what went wrong and hot to solve the issue:

    Error: Cannot connect
    
    I couldn't connect to database `database` with user `postgres`.
    
    Hint: You can change the default user and database by setting the `PGUSER` and
    `PGDATABASE` environment variables.
    

    (Giacomo Cavalieri)

v1.0.1 - 2024-08-09#

v1.0.0 - 2024-08-09#

  • ๐ŸŽ‰ First release!