Replies: 1 comment
-
|
Something like this would probably work: import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
jsonbBuildObject :: [(Expr Text, Expr Value)] -> Expr Value
jsonbBuildObject fields =
unsafePrimExpr
$ Opaleye.FunExpr "jsonb_build_object"
$ foldMap (\(k,v) -> [toPrimExpr k, toPrimExpr v]) fieldsSo with the latest version of Rel8 I'm halfway there now that it exports |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
So I've been struggling to implement postgresql's
jsonb_build_objectvia Rel8'sfunction. (I'm trying to construct a JSON object inside a query so if there's another way to do this that I'm missing, do let me know.)The issue is that that the arguments to
jsonb_build_objectare in fact variadic. Now I can do something like the following...And that will work. But let's say I want to build an object with more fields like this:
And now that won't compile because I've got a tuple that's too big. And even if it worked it's still a tedious way to build objects. Ideally I would like to create a function that looks like the following:
But I just can't figure out how to make this work with the functions currently exported by the library.
Beta Was this translation helpful? Give feedback.
All reactions