@@ -22,12 +22,10 @@ import qualified Opaleye.Internal.HaskellDB.PrimQuery as Opaleye
23import Rel8.Expr ( Expr( Expr ) )
23import Rel8.Expr ( Expr( Expr ) )
24import Rel8.Expr.Bool ( (&&.), (||.), coalesce )
24import Rel8.Expr.Bool ( (&&.), (||.), coalesce )
25−import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNullable )
25+import Rel8.Expr.Null ( isNull, isNonNull, nullable, unsafeLiftOpNull )
26import Rel8.Expr.Opaleye ( zipPrimExprsWith )
26import Rel8.Expr.Opaleye ( zipPrimExprsWith )
27−import Rel8.Schema.Nullability
27+import Rel8.Schema.Null ( Nullity( Null, NotNull ), Sql )
28− ( Nullability( NonNullable, Nullable )
28+import qualified Rel8.Schema.Null as Schema ( nullable )
29− , Sql, nullabilization
31import Rel8.Type.Ord ( DBOrd )
29import Rel8.Type.Ord ( DBOrd )
@@ -51,9 +49,9 @@ ge = zipPrimExprsWith (Opaleye.BinExpr (Opaleye.:>=))
51-- as @null@ will sort below any other value. For a version of @<@ that exactly
49-- as @null@ will sort below any other value. For a version of @<@ that exactly
52-- matches SQL, see '(<?)'.
50-- matches SQL, see '(<?)'.
53(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
51(<.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
54−(<.) = case nullabilization @a of
52+(<.) = case Schema.nullable @a of
55− Nullable -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
53+ Null -> \ma mb -> isNull ma &&. isNonNull mb ||. ma <? mb
56− NonNullable -> lt
54+ NotNull -> lt
@@ -61,9 +59,9 @@ infix 4 <.
61-- as @null@ will sort below any other value. For a version of @<=@ that exactly
59-- as @null@ will sort below any other value. For a version of @<=@ that exactly
62-- matches SQL, see '(<=?)'.
60-- matches SQL, see '(<=?)'.
63(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
61(<=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
64−(<=.) = case nullabilization @a of
62+(<=.) = case Schema.nullable @a of
65− Nullable -> \ma mb -> isNull ma ||. ma <=? mb
63+ Null -> \ma mb -> isNull ma ||. ma <=? mb
66− NonNullable -> le
64+ NotNull -> le
67infix 4 <=.
65infix 4 <=.
@@ -71,9 +69,9 @@ infix 4 <=.
71-- as @null@ will sort below any other value. For a version of @>@ that exactly
69-- as @null@ will sort below any other value. For a version of @>@ that exactly
72-- matches SQL, see '(>?)'.
70-- matches SQL, see '(>?)'.
73(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
71(>.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
74−(>.) = case nullabilization @a of
72+(>.) = case Schema.nullable @a of
75− Nullable -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
73+ Null -> \ma mb -> isNonNull ma &&. isNull mb ||. ma >? mb
76− NonNullable -> gt
74+ NotNull -> gt
@@ -81,37 +79,37 @@ infix 4 >.
81-- as @null@ will sort below any other value. For a version of @>=@ that
79-- as @null@ will sort below any other value. For a version of @>=@ that
82-- exactly matches SQL, see '(>=?)'.
80-- exactly matches SQL, see '(>=?)'.
83(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
81(>=.) :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr Bool
84−(>=.) = case nullabilization @a of
82+(>=.) = case Schema.nullable @a of
85− Nullable -> \ma mb -> isNull mb ||. ma >=? mb
83+ Null -> \ma mb -> isNull mb ||. ma >=? mb
86− NonNullable -> ge
84+ NotNull -> ge
87infix 4 >=.
85infix 4 >=.
90-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
88-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
91-- are @null@.
89-- are @null@.
92(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
90(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
93−a <? b = coalesce $ unsafeLiftOpNullable lt a b
91+a <? b = coalesce $ unsafeLiftOpNull lt a b
97-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
95-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
98-- are @null@.
96-- are @null@.
99(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
97(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
100−a <=? b = coalesce $ unsafeLiftOpNullable le a b
98+a <=? b = coalesce $ unsafeLiftOpNull le a b
101infix 4 <=?
99infix 4 <=?
104-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
102-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
105-- are @null@.
103-- are @null@.
106(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
104(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
107−a >? b = coalesce $ unsafeLiftOpNullable gt a b
105+a >? b = coalesce $ unsafeLiftOpNull gt a b
108infix 4 >?
106infix 4 >?
111-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
109-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
112-- are @null@.
110-- are @null@.
113(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
111(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
114−a >=? b = coalesce $ unsafeLiftOpNullable ge a b
112+a >=? b = coalesce $ unsafeLiftOpNull ge a b
115infix 4 >=?
113infix 4 >=?
@@ -120,9 +118,9 @@ infix 4 >=?
121-- Corresponds to the SQL @least()@ function.
119-- Corresponds to the SQL @least()@ function.
122leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
123−leastExpr ma mb = case nullabilization @a of
121+leastExpr ma mb = case Schema.nullable @a of
124− Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
122+ Null -> nullable ma (\a -> nullable mb (least_ a) mb) ma
125− NonNullable -> least_ ma mb
123+ NotNull -> least_ ma mb
127 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
125 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
@@ -132,8 +130,8 @@ leastExpr ma mb = case nullabilization @a of
133-- Corresponds to the SQL @greatest()@ function.
131-- Corresponds to the SQL @greatest()@ function.
134greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
132greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
135−greatestExpr ma mb = case nullabilization @a of
133+greatestExpr ma mb = case Schema.nullable @a of
136− Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
134+ Null -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
137− NonNullable -> greatest_ ma mb
135+ NotNull -> greatest_ ma mb
139 greatest_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "GREATEST" [a, b])
137 greatest_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "GREATEST" [a, b])