1{-# language FlexibleContexts #-}
2{-# language FlexibleInstances #-}
3{-# language MultiParamTypeClasses #-}
4{-# language StandaloneKindSignatures #-}
5{-# language TypeFamilies #-}
6{-# language UndecidableInstances #-}
8module Rel8.Expr.Function
12 , unsafeBinaryOperator
17import Data.Kind ( Constraint, Type )
21import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
24import Rel8.Expr ( Expr( Expr ) )
25import Rel8.Expr.Opaleye
27 , fromPrimExpr, toPrimExpr, zipPrimExprsWith
28 , unsafeZipPrimExprsWith
30import Rel8.Kind.Bool ( KnownBool, IsList )
31import Rel8.Schema.Nullability ( Nullabilizes )
32import Rel8.Type ( DBType )
35type Function :: Type -> Type -> Constraint
36class Function arg res where
37 applyArgument :: ([Opaleye.PrimExpr] -> Opaleye.PrimExpr) -> arg -> res
42 , Nullabilizes _a a, KnownBool (IsList _a)
43 , DBType _b, Nullabilizes _b b, KnownBool (IsList _b)
45 => Function arg (Expr b)
47 applyArgument f a = castExpr $ fromPrimExpr $ f [toPrimExpr a]
52 , Nullabilizes _a a, KnownBool (IsList _a)
55 Function arg (args -> res)
57 applyArgument f a = applyArgument (f . (toPrimExpr a :))
60function :: Function args result => String -> args -> result
61function = applyArgument . Opaleye.FunExpr
64nullaryFunction :: (DBType db, Nullabilizes db a) => String -> Expr a
65nullaryFunction name = castExpr $ Expr (Opaleye.FunExpr name [])
69 ( Nullabilizes _a a, KnownBool (IsList _a)
70 , Nullabilizes _b b, KnownBool (IsList _b)
71 , DBType _c, Nullabilizes _c c, KnownBool (IsList _c)
73 => String -> Expr a -> Expr b -> Expr c
74binaryOperator operator a b =
75 castExpr $ zipPrimExprsWith (Opaleye.BinExpr (Opaleye.OpOther operator)) a b
78unsafeBinaryOperator :: (DBType _c, Nullabilizes _c c)
79 => String -> Expr a -> Expr b -> Expr c
80unsafeBinaryOperator operator a b =
81 castExpr $ unsafeZipPrimExprsWith (Opaleye.BinExpr (Opaleye.OpOther operator)) a b
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