--- version: 1.3.0 title: enum array decoding file: ./test/squirrel_test.gleam test_name: enum_array_decoding_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(res: List(SquirrelColour)) } /// 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 res <- decode.field(0, decode.list(squirrel_colour_decoder())) decode.success(QueryRow(res:)) } "select array['red'::squirrel_colour] as res" |> pog.query |> pog.returning(decoder) |> pog.execute(db) } // --- Enums ------------------------------------------------------------------- /// Corresponds to the Postgres `squirrel_colour` enum. /// /// > 🐿️ This type definition was generated automatically using v-test of the /// > [squirrel package](https://github.com/giacomocavalieri/squirrel). /// pub type SquirrelColour { LightBrown Grey Red } fn squirrel_colour_decoder() { use squirrel_colour <- decode.then(decode.string) case squirrel_colour { "light brown" -> decode.success(LightBrown) "grey" -> decode.success(Grey) "red" -> decode.success(Red) _ -> decode.failure(LightBrown, "SquirrelColour") } }