Skip to content

Decoding JSONB to Aeson.Value #357

Answered by magthe
magthe asked this question in Q&A
Discussion options

You must be logged in to vote

Based on some suggestions on the discourse, and a bit of stubbornness on my side (it just didn't feel like using JSONB should require writing my own newtype wrappers, it ought to have support in squeal already) I came up with this modified definition of getValues:

getValues :: Statement MySchema Int32 (Int32, Aeson.Value)
getValues = Query encode decode sql
  where
    encode = (\x -> x) .* nilParams
    decode = mkResult <$> #id <*> #vals
    mkResult id_ vals = (id_, getJsonb vals)

Is that a good way to solve it, or is there a more idiomatic way?

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@echatav
Comment options

Answer selected by echatav
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants