on dev help sign in
3vl

`Condition`s are now `'Null 'PGbool` expressions.

commitf7aedef148049dd4fe024c08e2dc34cf98bc869c authorEitan Chatav <eitan.chatav@gmail.com> dateTue 14 Aug 2018, 17:59 (8 years ago) parent47d210e
1 file changed+41−42
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+41−42
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+41−42
@@ -351,7 +351,7 @@ null_ = UnsafeExpression "NULL"
351351
352352-- | analagous to `Just`
353353--
354−-- >>> printSQL $ notNull true
354+-- >>> printSQL $ true
355355-- TRUE
356356notNull
357357 :: Expression schema rels grouping params ('NotNull ty)
@@ -360,7 +360,7 @@ notNull = UnsafeExpression . renderExpression
360360
361361-- | return the leftmost value which is not NULL
362362--
363−-- >>> printSQL $ coalesce [null_, notNull true] false
363+-- >>> printSQL $ coalesce [null_, true] false
364364-- COALESCE(NULL, TRUE, FALSE)
365365coalesce
366366 :: [Expression schema relations grouping params ('Null ty)]
@@ -431,7 +431,7 @@ nullIf
431431nullIf x y = UnsafeExpression $ "NULL IF" <+> parenthesized
432432 (renderExpression x <> ", " <> renderExpression y)
433433
434−-- | >>> printSQL $ array [null_, notNull false, notNull true]
434+-- | >>> printSQL $ array [null_, false, true]
435435-- ARRAY[NULL, FALSE, TRUE]
436436array
437437 :: [Expression schema relations grouping params ty]
@@ -693,28 +693,27 @@ ceiling_
693693 -> Expression schema relations grouping params (nullity frac)
694694ceiling_ = unsafeFunction "ceiling"
695695
696−-- | A `Condition` is a boolean valued `Expression`. While SQL allows
697−-- conditions to have @NULL@, Squeal instead chooses to disallow @NULL@,
698−-- forcing one to handle the case of @NULL@ explicitly to produce
699−-- a `Condition`.
696+-- | A `Condition` is an `Expression`, which can evaluate
697+-- to `TRUE`, `FALSE` or `NULL`. This is because SQL uses
698+-- a three valued logic.
700699type Condition schema relations grouping params =
701− Expression schema relations grouping params ('NotNull 'PGbool)
700+ Expression schema relations grouping params ('Null 'PGbool)
702701
703702-- | >>> printSQL true
704703-- TRUE
705−true :: Condition schema relations grouping params
704+true :: Expression schema relations grouping params (nullity 'PGbool)
706705true = UnsafeExpression "TRUE"
707706
708707-- | >>> printSQL false
709708-- FALSE
710−false :: Condition schema relations grouping params
709+false :: Expression schema relations grouping params (nullity 'PGbool)
711710false = UnsafeExpression "FALSE"
712711
713712-- | >>> printSQL $ not_ true
714713-- (NOT TRUE)
715714not_
716− :: Condition schema relations grouping params
717− -> Condition schema relations grouping params
715+ :: Expression schema relations grouping params (nullity 'PGbool)
716+ -> Expression schema relations grouping params (nullity 'PGbool)
718717not_ = unsafeUnaryOp "NOT"
719718
720719-- | >>> printSQL $ true .&& false
@@ -742,12 +741,12 @@ not_ = unsafeUnaryOp "NOT"
742741-- CASE WHEN TRUE THEN 1 WHEN FALSE THEN 2 ELSE 3 END
743742caseWhenThenElse
744743 :: [ ( Condition schema relations grouping params
745− , Expression schema relations grouping params (ty)
744+ , Expression schema relations grouping params ty
746745 ) ]
747746 -- ^ whens and thens
748− -> Expression schema relations grouping params (ty)
747+ -> Expression schema relations grouping params ty
749748 -- ^ else
750− -> Expression schema relations grouping params (ty)
749+ -> Expression schema relations grouping params ty
751750caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
752751 [ "CASE"
753752 , mconcat
@@ -770,65 +769,65 @@ caseWhenThenElse whenThens else_ = UnsafeExpression $ mconcat
770769-- CASE WHEN TRUE THEN 1 ELSE 0 END
771770ifThenElse
772771 :: Condition schema relations grouping params
773− -> Expression schema relations grouping params (ty) -- ^ then
774− -> Expression schema relations grouping params (ty) -- ^ else
775− -> Expression schema relations grouping params (ty)
772+ -> Expression schema relations grouping params ty -- ^ then
773+ -> Expression schema relations grouping params ty -- ^ else
774+ -> Expression schema relations grouping params ty
776775ifThenElse if_ then_ else_ = caseWhenThenElse [(if_,then_)] else_
777776
778777-- | Comparison operations like `.==`, `./=`, `.>`, `.>=`, `.<` and `.<=`
779778-- will produce @NULL@s if one of their arguments is @NULL@.
780779--
781−-- >>> printSQL $ notNull true .== null_
780+-- >>> printSQL $ true .== null_
782781-- (TRUE = NULL)
783782(.==)
784− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
785− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
786− -> Expression schema relations grouping params (nullity 'PGbool)
783+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
784+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
785+ -> Condition schema relations grouping params
787786(.==) = unsafeBinaryOp "="
788787infix 4 .==
789788
790−-- | >>> printSQL $ notNull true ./= null_
789+-- | >>> printSQL $ true ./= null_
791790-- (TRUE <> NULL)
792791(./=)
793− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
794− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
795− -> Expression schema relations grouping params (nullity 'PGbool)
792+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
793+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
794+ -> Condition schema relations grouping params
796795(./=) = unsafeBinaryOp "<>"
797796infix 4 ./=
798797
799−-- | >>> printSQL $ notNull true .>= null_
798+-- | >>> printSQL $ true .>= null_
800799-- (TRUE >= NULL)
801800(.>=)
802− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
803− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
804− -> Expression schema relations grouping params (nullity 'PGbool)
801+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
802+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
803+ -> Condition schema relations grouping params
805804(.>=) = unsafeBinaryOp ">="
806805infix 4 .>=
807806
808−-- | >>> printSQL $ notNull true .< null_
807+-- | >>> printSQL $ true .< null_
809808-- (TRUE < NULL)
810809(.<)
811− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
812− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
813− -> Expression schema relations grouping params (nullity 'PGbool)
810+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
811+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
812+ -> Condition schema relations grouping params
814813(.<) = unsafeBinaryOp "<"
815814infix 4 .<
816815
817−-- | >>> printSQL $ notNull true .<= null_
816+-- | >>> printSQL $ true .<= null_
818817-- (TRUE <= NULL)
819818(.<=)
820− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
821− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
822− -> Expression schema relations grouping params (nullity 'PGbool)
819+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
820+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
821+ -> Condition schema relations grouping params
823822(.<=) = unsafeBinaryOp "<="
824823infix 4 .<=
825824
826−-- | >>> printSQL $ notNull true .> null_
825+-- | >>> printSQL $ true .> null_
827826-- (TRUE > NULL)
828827(.>)
829− :: Expression schema relations grouping params (nullity ty) -- ^ lhs
830− -> Expression schema relations grouping params (nullity ty) -- ^ rhs
831− -> Expression schema relations grouping params (nullity 'PGbool)
828+ :: Expression schema relations grouping params (nullity0 ty) -- ^ lhs
829+ -> Expression schema relations grouping params (nullity1 ty) -- ^ rhs
830+ -> Condition schema relations grouping params
832831(.>) = unsafeBinaryOp ">"
833832infix 4 .>
834833