@@ -32,8 +32,8 @@ module Squeal.PostgreSQL.Expression
3232 Expression (UnsafeExpression, renderExpression)
3333 , HasParameter (param)
3434 -- ** Null
35− , null_
36− , unNull
35+ , HasNull (null_)
36+ , HasNotNull (notNull)
3737 , coalesce
3838 , fromNull
3939 , isNull
@@ -221,26 +221,28 @@ instance
221221 relation ! column = UnsafeExpression $
222222 renderAlias relation <> "." <> renderAlias column
223223
224−-- | analagous to `Nothing`
225−--
226−-- >>> renderExpression $ null_
227−-- "NULL"
228−null_ :: Expression relations grouping params ('Null ty)
229−null_ = UnsafeExpression "NULL"
230−
231−-- | analagous to `Just`
232−--
233−-- >>> renderExpression $ unNull true
234−-- "TRUE"
235−unNull
236− :: Expression relations grouping params ('NotNull ty)
237− -- ^ not @NULL@
238− -> Expression relations grouping params ('Null ty)
239−unNull = UnsafeExpression . renderExpression
224+class HasNull expr where null_ :: expr
225+instance HasNull (Expression rels grouping params ('Null ty)) where
226+ -- | analagous to `Nothing`
227+ --
228+ -- >>> renderExpression $ null_
229+ -- "NULL"
230+ null_ = UnsafeExpression "NULL"
231+
232+class HasNotNull expr where notNull :: expr
233+instance HasNotNull
234+ ( Expression rels grouping params ('NotNull ty)
235+ ->
236+ Expression rels grouping params ('Null ty) ) where
237+ -- | analagous to `Just`
238+ --
239+ -- >>> renderExpression $ notNull true
240+ -- "TRUE"
241+ notNull = UnsafeExpression . renderExpression
240242
241243-- | return the leftmost value which is not NULL
242244--
243−-- >>> renderExpression $ coalesce [null_, unNull true] false
245+-- >>> renderExpression $ coalesce [null_, notNull true] false
244246-- "COALESCE(NULL, TRUE, FALSE)"
245247coalesce
246248 :: [Expression relations grouping params ('Null ty)]
@@ -309,7 +311,7 @@ nullIf
309311nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
310312 (renderExpression x <> ", " <> renderExpression y)
311313
312−-- | >>> renderExpression $ array [null_, unNull false, unNull true]
314+-- | >>> renderExpression $ array [null_, notNull false, notNull true]
313315-- "ARRAY[NULL, FALSE, TRUE]"
314316array
315317 :: [Expression relations grouping params ('Null ty)]
@@ -628,7 +630,7 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
628630-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
629631-- will produce @NULL@s if one of their arguments is @NULL@.
630632--
631−-- >>> renderExpression $ unNull true .== null_
633+-- >>> renderExpression $ notNull true .== null_
632634-- "(TRUE = NULL)"
633635(.==)
634636 :: Expression relations grouping params (nullity ty) -- ^ lhs
@@ -637,7 +639,7 @@ ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
637639(.==) = unsafeBinaryOp "="
638640infix 4 .==
639641
640−-- | >>> renderExpression $ unNull true ./= null_
642+-- | >>> renderExpression $ notNull true ./= null_
641643-- "(TRUE <> NULL)"
642644(./=)
643645 :: Expression relations grouping params (nullity ty) -- ^ lhs
@@ -646,7 +648,7 @@ infix 4 .==
646648(./=) = unsafeBinaryOp "<>"
647649infix 4 ./=
648650
649−-- | >>> renderExpression $ unNull true .>= null_
651+-- | >>> renderExpression $ notNull true .>= null_
650652-- "(TRUE >= NULL)"
651653(.>=)
652654 :: Expression relations grouping params (nullity ty) -- ^ lhs
@@ -655,7 +657,7 @@ infix 4 ./=
655657(.>=) = unsafeBinaryOp ">="
656658infix 4 .>=
657659
658−-- | >>> renderExpression $ unNull true .< null_
660+-- | >>> renderExpression $ notNull true .< null_
659661-- "(TRUE < NULL)"
660662(.<)
661663 :: Expression relations grouping params (nullity ty) -- ^ lhs
@@ -664,7 +666,7 @@ infix 4 .>=
664666(.<) = unsafeBinaryOp "<"
665667infix 4 .<
666668
667−-- | >>> renderExpression $ unNull true .<= null_
669+-- | >>> renderExpression $ notNull true .<= null_
668670-- "(TRUE <= NULL)"
669671(.<=)
670672 :: Expression relations grouping params (nullity ty) -- ^ lhs
@@ -673,7 +675,7 @@ infix 4 .<
673675(.<=) = unsafeBinaryOp "<="
674676infix 4 .<=
675677
676−-- | >>> renderExpression $ unNull true .> null_
678+-- | >>> renderExpression $ notNull true .> null_
677679-- "(TRUE > NULL)"
678680(.>)
679681 :: Expression relations grouping params (nullity ty) -- ^ lhs