Added case_ operator

Add `case_` operator which maps through
directly to the opaley `case_` operator.
This commit is contained in:
Handré Stolp 2017-02-13 13:23:24 +02:00
parent 801d7901d1
commit 99d4a0b9bc
2 changed files with 9 additions and 1 deletions

View File

@ -91,7 +91,7 @@ module Rel8
-- * TODO Organise
, QueryResult, Schema, Anon
, QueryResult, Schema, Anon, case_
-- * Re-exported symbols
, Connection, Stream, Of, Generic

View File

@ -6,6 +6,7 @@
module Rel8.Internal.Operators where
import Control.Arrow ((***))
import Data.Int (Int16, Int32, Int64)
import Data.Text (Text)
import Data.Time (UTCTime)
@ -86,3 +87,10 @@ instance DBOrd Int64 where
instance DBOrd Text where
instance DBOrd UTCTime where
-- | Case statement
case_ :: [(Expr Bool, Expr a)] -> Expr a -> Expr a
case_ cases defaultCase =
columnToExpr
(O.case_
(map (exprToColumn *** exprToColumn) cases)
(exprToColumn defaultCase))