4 ms·
Arbitrary nesting is supported module Main where import Rel8 import Data.Int import Hasql.Statement import Hasql.Session import Ha
by tome 5y ago
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])])])
- tome 5y agoHaving 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.