From bcd05bd348ccef9cfd1e99601da5f0ffd5eeade8 Mon Sep 17 00:00:00 2001 From: Kei Hibino Date: Tue, 21 May 2013 10:56:08 +0900 Subject: [PATCH] Update example. --- .../sample/1/querySample.hs | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/relational-join-HDBC-pgTest/sample/1/querySample.hs b/relational-join-HDBC-pgTest/sample/1/querySample.hs index 1f85a2d0..7d1fd510 100644 --- a/relational-join-HDBC-pgTest/sample/1/querySample.hs +++ b/relational-join-HDBC-pgTest/sample/1/querySample.hs @@ -17,8 +17,9 @@ import Database.HDBC.Record.Query (runQuery) import Database.HDBC.Session (withConnectionIO) -groupMemberShip :: QueryJoin (Projection (Maybe Membership, Group)) +groupMemberShip :: Relation (Maybe Membership, Group) groupMemberShip = + relation $ [ m >*< g | m <- queryMaybe membership , g <- query group @@ -30,30 +31,30 @@ userGroup0 = relation $ [ u >*< mg !? snd' | u <- queryMaybe user - , mg <- queryMaybe $ relation groupMemberShip + , mg <- queryMaybe $ nested groupMemberShip -- Call one subquery via relation layer -- Simple implementation. - -- Complex SQL. Nested table form joins. + -- Nested SQL. Nested table form joins. , () <- on $ u !? User.id' .=. flatten (mg !? fst') !? userId' , () <- asc $ u !? User.id' ] --- userGroup1 :: Relation (Maybe User, Maybe Group) --- userGroup1 = --- relation $ --- [ u >*< mg !? snd' --- | u <- queryMaybe user --- , mg <- queryMergeMaybe groupMemberShip --- -- Directly merge another QueryJoin monad. --- -- Complex implementation. --- -- Simple SQL. Flat table form joins. +userGroup1 :: Relation (Maybe User, Maybe Group) +userGroup1 = + relation $ + [ u >*< mg !? snd' + | u <- queryMaybe user + , mg <- queryMaybe groupMemberShip + -- Directly merge another QueryJoin monad. + -- Complex implementation. + -- Flat SQL. Flat table form joins. --- , () <- on $ u !? User.id' .=. flatten (mg !? fst') !? userId' + , () <- on $ u !? User.id' .=. flatten (mg !? fst') !? userId' --- , () <- asc $ u !? User.id' --- ] + , () <- asc $ u !? User.id' + ] runAndPrint :: (Show a, IConnection conn, FromSql SqlValue a) => conn -> Relation a -> IO () runAndPrint conn rel = do @@ -66,7 +67,7 @@ run :: IO () run = withConnectionIO connect (\conn -> do runAndPrint conn userGroup0 --- runAndPrint conn userGroup1 + runAndPrint conn userGroup1 ) main :: IO ()