Chain configuration into queryList.

This commit is contained in:
Kei Hibino 2013-09-06 12:23:41 +09:00
parent 751712f7d5
commit 2d073d92e3
2 changed files with 18 additions and 10 deletions

View File

@ -73,8 +73,9 @@ haskellUser =
| ug <- query userGroup0
, () <- wheres $ ug ! snd' ?!? Group.name' .=. just (value "Haskell")
]
, hu <- query hus
, () <- wheres . exists . queryList $ hus
, hu <- query hus
, hul <- queryList hus
, () <- wheres $ exists hul
]
-- Direct join style
@ -168,13 +169,14 @@ user3 =
userGroupAggregate1 :: Relation () ((Maybe String, Int32), Maybe Bool)
userGroupAggregate1 =
aggregateRelation $
[ g >< c >< every (uid `in'` queryList user3)
[ g >< c >< every (uid `in'` us)
| ug <- query userGroup0
, g <- groupBy (ug ! snd' ?!? Group.name')
, let uid = ug ! fst' ?! User.id'
, let c = count uid
, () <- having $ c `in'` values [1, 2]
, () <- asc $ c
, us <- queryList user3
]
-- Concatinate operator

View File

@ -38,8 +38,6 @@ module Database.Relational.Query.Relation (
union', except', intersect'
) where
import Control.Arrow ((&&&))
import Database.Relational.Query.Context (Flat, Aggregated)
import Database.Relational.Query.Monad.Type (ConfigureQuery, configureQuery, qualifyQuery)
import Database.Relational.Query.Monad.Class
@ -116,15 +114,23 @@ queryMaybe' pr = do
queryMaybe :: MonadQualify ConfigureQuery m => Relation () r -> m (Projection Flat (Maybe r))
queryMaybe = fmap snd . queryMaybe'
queryList0 :: Relation p r -> ListProjection (Projection c) r
queryList0 = unsafeListProjectionFromSubQuery . configureQuery . subQueryQualifyFromRelation
queryList0 :: MonadQualify ConfigureQuery m => Relation p r -> m (ListProjection (Projection c) r)
queryList0 = liftQualify
. fmap unsafeListProjectionFromSubQuery
. subQueryQualifyFromRelation
-- | List subQuery, for /IN/ and /EXIST/ with place-holder parameter 'p'.
queryList' :: Relation p r -> (PlaceHolders p, ListProjection (Projection c) r)
queryList' = placeHoldersFromRelation &&& queryList0
queryList' :: MonadQualify ConfigureQuery m
=> Relation p r
-> m (PlaceHolders p, ListProjection (Projection c) r)
queryList' rel = do
ql <- queryList0 rel
return (placeHoldersFromRelation rel, ql)
-- | List subQuery, for /IN/ and /EXIST/.
queryList :: Relation () r -> ListProjection (Projection c) r
queryList :: MonadQualify ConfigureQuery m
=> Relation () r
-> m (ListProjection (Projection c) r)
queryList = queryList0
-- | Finalize 'QuerySimple' monad and generate 'Relation'.