on fce7213 help sign in
rel8/src/Rel8/Query/Filter.hs
39 lines 811 B history raw
1module Rel8.Query.Filter
2 ( filter
3 , where_
4 )
5where
7-- base
8import Prelude hiding ( filter )
10-- opaleye
11import qualified Opaleye.Operators as Opaleye
13-- profunctors
14import Data.Profunctor ( lmap )
16-- rel8
17import Rel8.Expr ( Expr )
18import Rel8.Expr.Opaleye ( toColumn, toPrimExpr )
19import Rel8.Query ( Query )
20import Rel8.Query.Opaleye ( fromOpaleye )
23filter :: (a -> Expr Bool) -> a -> Query a
24filter f a = a <$ where_ (f a)
27-- | Drop any rows that don't match a predicate. @where_ expr@ is equivalent
28-- to the SQL @WHERE expr@.
29--
30-- >>> :{
31-- select c $ do
32-- x <- values [ lit x | x <- [ 1..5 :: Int32 ] ]
33-- where_ $ x >. lit 2
34-- return x
35-- :}
36-- [3,4,5]
37where_ :: Expr Bool -> Query ()
38where_ condition =
39 fromOpaleye $ lmap (\_ -> toColumn $ toPrimExpr condition) Opaleye.restrict