Re:Haskell2020 Is Dead, but All Hope Is Not Lost (2019)
by jeremyjh on Thursday February 17, 2022 @05:37PM
(#30379646)
That's awesome, thanks for linking it to me. I don't think I have seen this library before, looks like its fairly new. I have to admit from the signature I can't tell if I can nest these arbitrarily deep, it looks like I can?
[ Parent
| on HN ]
Re:Haskell2020 Is Dead, but All Hope Is Not Lost (2019)
by tome on Friday February 18, 2022 @03:34AM
(#30383417)
Arbitrary nesting is supported
module Main where
import Rel8
import Data.Int
import Hasql.Statement
import Hasql.Session
import Hasql.Connection
import Database.Postgres.Temp
main = Database.Postgres.Temp.with $ \db -> do
Right conn <- acquire (toConnectionString db)
flip run conn $ statement () $ select $ do
q1 <- many $ do
r1 <- many (values [1 , 2 :: Expr Int16])
r2 <- many (values [3 , 4 :: Expr Int16])
values [(litExpr "one", r1), (litExpr "two", r2)]
q2 <- many $ do
r1 <- many (values [10 , 20 :: Expr Int16])
r2 <- many (values [30 , 40 :: Expr Int16])
values [(litExpr "ten", r1), (litExpr "twenty", r2)]
values [(litExpr "X", q1), (litExpr "Y", q2)]
> main
Right (Right [("X",[("one",[1,2]),("two",[3,4])]),("Y",[("ten",[10,20]),("twenty",[30,40])])])
Re:Haskell2020 Is Dead, but All Hope Is Not Lost (2019)
by tome on Friday February 18, 2022 @03:41AM
(#30383449)
Having said that, Postgres supports JSON fine, and Opaleye and Rel8 support Postgres's JSON fine, so you can just use that if you want arbitrarily structured and nested stuff.
Re:Haskell2020 Is Dead, but All Hope Is Not Lost (2019)
by ParetoOptimal on Friday February 18, 2022 @01:23AM
(#30382694)
Rel8 is pretty new, but it's built on top of opaleye which is much older.