···99 with a `do` block.
1010 ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
11111212+- Fixed a bug where queries would not be generated in a reproducible order,
1313+ causing `squirrel check` to fail unexpectedly.
1414+ ([Giacomo Cavalieri](https://github.com/giacomocavalieri))
1515+1216## 4.0.1 - 2025-07-14
13171418- Fixed a bug where using numeric types in a query would result in runtime
···11+---
22+version: 1.3.2
33+title: queries are sorted alphabetically
44+file: ./test/squirrel_test.gleam
55+test_name: queries_are_sorted_alphabetically_test
66+---
77+import gleam/dynamic/decode
88+import pog
99+1010+/// A row you get from running the `first` query
1111+/// defined in `first.sql`.
1212+///
1313+/// > 🐿️ This type definition was generated automatically using v-test of the
1414+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
1515+///
1616+pub type FirstRow {
1717+ FirstRow(wibble: Int)
1818+}
1919+2020+/// Runs the `first` query
2121+/// defined in `first.sql`.
2222+///
2323+/// > 🐿️ This function was generated automatically using v-test of
2424+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
2525+///
2626+pub fn first(db) {
2727+ let decoder = {
2828+ use wibble <- decode.field(0, decode.int)
2929+ decode.success(FirstRow(wibble:))
3030+ }
3131+3232+ "select 1 as wibble"
3333+ |> pog.query
3434+ |> pog.returning(decoder)
3535+ |> pog.execute(db)
3636+}
3737+3838+/// A row you get from running the `last` query
3939+/// defined in `last.sql`.
4040+///
4141+/// > 🐿️ This type definition was generated automatically using v-test of the
4242+/// > [squirrel package](https://github.com/giacomocavalieri/squirrel).
4343+///
4444+pub type LastRow {
4545+ LastRow(wibble: Int)
4646+}
4747+4848+/// Runs the `last` query
4949+/// defined in `last.sql`.
5050+///
5151+/// > 🐿️ This function was generated automatically using v-test of
5252+/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel).
5353+///
5454+pub fn last(db) {
5555+ let decoder = {
5656+ use wibble <- decode.field(0, decode.int)
5757+ decode.success(LastRow(wibble:))
5858+ }
5959+6060+ "select 1 as wibble"
6161+ |> pog.query
6262+ |> pog.returning(decoder)
6363+ |> pog.execute(db)
6464+}
+7
src/squirrel/internal/query.gleam
···357357/// Generates the code for a single file containing a bunch of typed queries.
358358///
359359pub fn generate_code(queries: List(TypedQuery), version: String) -> String {
360360+ // We need to sort the queries before generating any code, otherwise the order
361361+ // with which they will appear in the generated file won't be reproducible!
362362+ // That could cause CI checks like `gleam run -m squirrel check` to fail.
363363+ //
364364+ let queries =
365365+ list.sort(queries, fn(one, other) { string.compare(one.file, other.file) })
366366+360367 let #(state, queries_docs) = {
361368 let state = default_codegen_state()
362369 use #(state, docs), query <- list.fold(over: queries, from: #(state, []))
+8
test/squirrel_test.gleam
···623623 )
624624}
625625626626+pub fn queries_are_sorted_alphabetically_test() {
627627+ should_codegen_queries([
628628+ #("last", "select 1 as wibble"),
629629+ #("first", "select 1 as wibble"),
630630+ ])
631631+ |> birdie.snap(title: "queries are sorted alphabetically")
632632+}
633633+626634// --- ERRROR TESTS ------------------------------------------------------------
627635// This is a group of tests to ensure that the errors look good when something
628636// goes wrong.