Something went wrong. Try again.
🐿️ Type safe SQL in Gleam
Something went wrong. Try again.
1.6 kB · 59 lines
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960---version: 1.3.0title: enum array decodingfile: ./test/squirrel_test.gleamtest_name: enum_array_decoding_test---import gleam/dynamic/decodeimport 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") }}