diff --git a/birdie_snapshots/query_with_quoted_string_is_properly_escaped.accepted b/birdie_snapshots/query_with_quoted_string_is_properly_escaped.accepted new file mode 100644 index 0000000..9eecb24 --- /dev/null +++ b/birdie_snapshots/query_with_quoted_string_is_properly_escaped.accepted @@ -0,0 +1,36 @@ +--- +version: 1.3.0 +title: query with quoted string is properly escaped +file: ./test/squirrel_test.gleam +test_name: query_with_quoted_string_is_properly_escaped_test +--- +import gleam/dynamic/decode +import pog + +/// A row you get from running the `query` query +/// defined in `query.sql`. +/// +/// > 🐿️ This type definition was generated automatically using v-test of the +/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). +/// +pub type QueryRow { + QueryRow(result: Int) +} + +/// Runs the `query` query +/// defined in `query.sql`. +/// +/// > 🐿️ This function was generated automatically using v-test of +/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). +/// +pub fn query(db) { + let decoder = { + use result <- decode.field(0, decode.int) + decode.success(QueryRow(result:)) + } + + "select 1 as \"result\"" + |> pog.query + |> pog.returning(decoder) + |> pog.execute(db) +} diff --git a/test/squirrel_test.gleam b/test/squirrel_test.gleam index 249b153..5a18c1c 100644 --- a/test/squirrel_test.gleam +++ b/test/squirrel_test.gleam @@ -551,6 +551,12 @@ pub fn query_that_needs_utils_and_enums_has_two_sections_test() { |> birdie.snap(title: "query that needs utils and enums has two sections") } +pub fn query_with_quoted_string_is_properly_escaped_test() { + "select 1 as \"result\"" + |> should_codegen + |> birdie.snap(title: "query with quoted string is properly escaped") +} + // --- ERRROR TESTS ------------------------------------------------------------ // This is a group of tests to ensure that the errors look good when something // goes wrong.