on master help sign in
Document ==: and /=:
commitb95dec4c32434072aae312144fe858706d20196d authorOllie Charles <ollie@ocharles.org.uk> dateWed 24 Mar 2021, 11:25 (6 years ago) parentbeca9e0
2 files changed+34−3
src/Rel8/Expr/Ord.hs+28−3 src/Rel8/Table/Eq.hs+6
src/Rel8/Expr/Ord.hs+28−3
@@ -73,49 +73,70 @@ sge = \case
7373 NonNullable -> ge
7474
7575
76+-- | Corresponds to the SQL @<@ operator. Note that this differs from SQL @<@
77+-- as @null@ will sort below any other value. For a version of @<@ that exactly
78+-- matches SQL, see '(<?)'.
7679(<.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
7780(<.) = slt nullabilization
7881infix 4 <.
7982
8083
81−-- | The PostgreSQL @<=@ operator.
84+-- | Corresponds to the SQL @<=@ operator. Note that this differs from SQL @<=@
85+-- as @null@ will sort below any other value. For a version of @<=@ that exactly
86+-- matches SQL, see '(<=?)'.
8287(<=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
8388(<=.) = sle nullabilization
8489infix 4 <=.
8590
8691
87−-- | The PostgreSQL @>@ operator.
92+-- | Corresponds to the SQL @>@ operator. Note that this differs from SQL @>@
93+-- as @null@ will sort below any other value. For a version of @>@ that exactly
94+-- matches SQL, see '(>?)'.
8895(>.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
8996(>.) = sgt nullabilization
9097infix 4 >.
9198
9299
93−-- | The PostgreSQL @>=@ operator.
100+-- | Corresponds to the SQL @>=@ operator. Note that this differs from SQL @>@
101+-- as @null@ will sort below any other value. For a version of @>=@ that
102+-- exactly matches SQL, see '(>=?)'.
94103(>=.) :: Sql DBOrd a => Expr a -> Expr a -> Expr Bool
95104(>=.) = sge nullabilization
96105infix 4 >=.
97106
98107
108+-- | Corresponds to the SQL @<@ operator. Returns @null@ if either arguments
109+-- are @null@.
99110(<?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
100111a <? b = coalesce $ unsafeLiftOpNullable lt a b
101112infix 4 <?
102113
103114
115+-- | Corresponds to the SQL @<=@ operator. Returns @null@ if either arguments
116+-- are @null@.
104117(<=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
105118a <=? b = coalesce $ unsafeLiftOpNullable le a b
106119infix 4 <=?
107120
108121
122+-- | Corresponds to the SQL @>@ operator. Returns @null@ if either arguments
123+-- are @null@.
109124(>?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
110125a >? b = coalesce $ unsafeLiftOpNullable gt a b
111126infix 4 >?
112127
113128
129+-- | Corresponds to the SQL @>=@ operator. Returns @null@ if either arguments
130+-- are @null@.
114131(>=?) :: DBOrd a => Expr (Maybe a) -> Expr (Maybe a) -> Expr Bool
115132a >=? b = coalesce $ unsafeLiftOpNullable ge a b
116133infix 4 >=?
117134
118135
136+-- | Given two expressions, return the expression that sorts less than the
137+-- other.
138+--
139+-- Corresponds to the SQL @least()@ function.
119140leastExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
120141leastExpr ma mb = case nullabilization @a of
121142 Nullable -> nullable ma (\a -> nullable mb (least_ a) mb) ma
@@ -124,6 +145,10 @@ leastExpr ma mb = case nullabilization @a of
124145 least_ (Expr a) (Expr b) = Expr (Opaleye.FunExpr "LEAST" [a, b])
125146
126147
148+-- | Given two expressions, return the expression that sorts greater than the
149+-- other.
150+--
151+-- Corresponds to the SQL @greatest()@ function.
127152greatestExpr :: forall a. Sql DBOrd a => Expr a -> Expr a -> Expr a
128153greatestExpr ma mb = case nullabilization @a of
129154 Nullable -> nullable mb (\a -> nullable ma (greatest_ a) mb) ma
src/Rel8/Table/Eq.hs+6
@@ -52,6 +52,9 @@ instance
5252instance {-# OVERLAPPING #-} EqTable Opaque
5353
5454
55+-- | Compare two 'Table's for equality. This corresponds to comparing all
56+-- columns inside each table for equality, and combining all comparisons with
57+-- @AND@.
5558(==:) :: forall a. EqTable a => a -> a -> Expr Bool
5659(toColumns -> as) ==: (toColumns -> bs) =
5760 foldl1' (&&.) $ getConst $ htabulateA $ \field ->
@@ -65,6 +68,9 @@ instance {-# OVERLAPPING #-} EqTable Opaque
6568infix 4 ==:
6669
6770
71+-- | Test if two 'Table's are different. This corresponds to comparing all
72+-- columns inside each table for inequality, and combining all comparisons with
73+-- @OR@.
6874(/=:) :: forall a. EqTable a => a -> a -> Expr Bool
6975(toColumns -> as) /=: (toColumns -> bs) =
7076 foldl1' (||.) $ getConst $ htabulateA $ \field ->