lpil / sqlight

💡 Use SQLite from Gleam!
https://hexdocs.pm/sqlight
79 stars 11 forks source link

Decoder failed, expected Int, got Tuple of 1 elements in #4

Closed rockerBOO closed 9 months ago

rockerBOO commented 9 months ago

Trying to get 1 element from a query but it's asking for a tuple of 1. There is no tuple1 in the dynamic so I tried dynamic.int but getting the following error.

SqlightError(GenericError, "Decoder failed, expected Int, got Tuple of 1 elements in ", -1)

Example code

 sqlight.query(
    "select score from image_scores where image = ?",
    conn,
    [sqlight.text(image)],
    expecting: dynamic.int,
  )
  |> result.map_error(fn(e) { io.debug(e) })

What is the expected behavior here?

Thank you!

lpil commented 9 months ago

The element function can be used to decode a single value from a tuple: https://hexdocs.pm/gleam_stdlib/gleam/dynamic.html#element

rockerBOO commented 9 months ago

Sweet, that works! I was getting in the weeds with json and sqlight and mixing them up. I was getting confused. This works and I like it. Thank you!