1{-# language DataKinds #-}
3module Rel8.Query.Exists
5 , whereExists, with, withBy
6 , whereNotExists, without, withoutBy
11import Prelude hiding ( filter )
14import qualified Opaleye.Operators as Opaleye
17import Rel8.Expr ( Expr )
18import Rel8.Query ( Query )
19import Rel8.Query.Filter ( filter )
20import Rel8.Query.Maybe ( optional )
21import Rel8.Query.Opaleye ( mapOpaleye )
22import Rel8.Table.Eq ( EqTable, (==:) )
23import Rel8.Table.Maybe ( isJustTable )
26exists :: Query a -> Query (Expr Bool)
27exists = fmap isJustTable . optional . whereExists
28-- FIXME: change this when b7aacc07c6392654cae439fc3b997620c3aa7a87 makes it
29-- into a release of Opaleye
32inQuery :: EqTable a => a -> Query a -> Query (Expr Bool)
33inQuery a = exists . (>>= filter (a ==:))
36whereExists :: Query a -> Query ()
37whereExists = mapOpaleye Opaleye.restrictExists
40whereNotExists :: Query a -> Query ()
41whereNotExists = mapOpaleye Opaleye.restrictNotExists
44with :: (a -> Query b) -> a -> Query a
45with f a = a <$ whereExists (f a)
48withBy :: (a -> b -> Expr Bool) -> Query b -> a -> Query a
49withBy predicate bs = with $ \a -> bs >>= filter (predicate a)
52without :: (a -> Query b) -> a -> Query a
53without f a = a <$ whereNotExists (f a)
56withoutBy :: (a -> b -> Expr Bool) -> Query b -> a -> Query a
57withoutBy predicate bs = without $ \a -> bs >>= filter (predicate a)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list