module Rel8.Query.Filter
( filter
, where_
)
where
import Prelude hiding ( filter )
import qualified Opaleye.Operators as Opaleye
import Data.Profunctor ( lmap )
import Rel8.Expr ( Expr )
import Rel8.Expr.Opaleye ( toColumn, toPrimExpr )
import Rel8.Query ( Query )
import Rel8.Query.Opaleye ( fromOpaleye )
filter :: (a -> Expr Bool) -> a -> Query a
filter :: (a -> Expr Bool) -> a -> Query a
filter a -> Expr Bool
f a
a = a
a a -> Query () -> Query a
forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ Expr Bool -> Query ()
where_ (a -> Expr Bool
f a
a)
where_ :: Expr Bool -> Query ()
where_ :: Expr Bool -> Query ()
where_ Expr Bool
condition =
Select () -> Query ()
forall a. Select a -> Query a
fromOpaleye (Select () -> Query ()) -> Select () -> Query ()
forall a b. (a -> b) -> a -> b
$ (() -> Column SqlBool)
-> SelectArr (Column SqlBool) () -> Select ()
forall (p :: * -> * -> *) a b c.
Profunctor p =>
(a -> b) -> p b c -> p a c
lmap (\()
_ -> PrimExpr -> Column SqlBool
forall b. PrimExpr -> Column b
toColumn (PrimExpr -> Column SqlBool) -> PrimExpr -> Column SqlBool
forall a b. (a -> b) -> a -> b
$ Expr Bool -> PrimExpr
forall a. Expr a -> PrimExpr
toPrimExpr Expr Bool
condition) SelectArr (Column SqlBool) ()
SelectArr (Field SqlBool) ()
Opaleye.restrict