on dev help sign in
comparisons and fixities
commitdcfe3ec39a92540d7e4aab2edc2b3685a12ca5b9 authorEitan Chatav <eitan@Eitans-MBP.local.tld> dateMon 4 Mar 2019, 10:53 (8 years ago) parent64748f9
1 file changed+138
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+138
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+138
@@ -80,6 +80,18 @@ module Squeal.PostgreSQL.Expression
8080 , (.<)
8181 , (.<=)
8282 , (.>)
83+ , between
84+ , notBetween
85+ , betweenSymmetric
86+ , notBetweenSymmetric
87+ , isDistinctFrom
88+ , isNotDistinctFrom
89+ , isTrue
90+ , isNotTrue
91+ , isFalse
92+ , isNotFalse
93+ , isUnknown
94+ , isNotUnknown
8395 -- ** Time
8496 , currentDate
8597 , currentTime
@@ -920,6 +932,128 @@ infix 4 .<=
920932(.>) = unsafeBinaryOp ">"
921933infix 4 .>
922934
935+{- | between
936+>>> printSQL $ true `between` (null_, false)
937+TRUE BETWEEN NULL AND FALSE
938+-}
939+between
940+ :: Expression outer grp commons schemas params from (nullity ty)
941+ -> ( Expression outer grp commons schemas params from (nullity ty)
942+ , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
943+ -> Condition outer grp commons schemas params from
944+between a (x,y) = UnsafeExpression $ renderSQL a <+> "BETWEEN"
945+ <+> renderSQL x <+> "AND" <+> renderSQL y
946+
947+{- | not between
948+>>> printSQL $ true `notBetween` (null_, false)
949+TRUE NOT BETWEEN NULL AND FALSE
950+-}
951+notBetween
952+ :: Expression outer grp commons schemas params from (nullity ty)
953+ -> ( Expression outer grp commons schemas params from (nullity ty)
954+ , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
955+ -> Condition outer grp commons schemas params from
956+notBetween a (x,y) = UnsafeExpression $ renderSQL a <+> "NOT BETWEEN"
957+ <+> renderSQL x <+> "AND" <+> renderSQL y
958+
959+{- | between, after sorting the comparison values
960+>>> printSQL $ true `betweenSymmetric` (null_, false)
961+TRUE BETWEEN SYMMETRIC NULL AND FALSE
962+-}
963+betweenSymmetric
964+ :: Expression outer grp commons schemas params from (nullity ty)
965+ -> ( Expression outer grp commons schemas params from (nullity ty)
966+ , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
967+ -> Condition outer grp commons schemas params from
968+betweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
969+ <+> "BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
970+
971+{- | not between, after sorting the comparison values
972+>>> printSQL $ true `notBetweenSymmetric` (null_, false)
973+TRUE NOT BETWEEN SYMMETRIC NULL AND FALSE
974+-}
975+notBetweenSymmetric
976+ :: Expression outer grp commons schemas params from (nullity ty)
977+ -> ( Expression outer grp commons schemas params from (nullity ty)
978+ , Expression outer grp commons schemas params from (nullity ty) ) -- ^ bounds
979+ -> Condition outer grp commons schemas params from
980+notBetweenSymmetric a (x,y) = UnsafeExpression $ renderSQL a
981+ <+> "NOT BETWEEN SYMMETRIC" <+> renderSQL x <+> "AND" <+> renderSQL y
982+
983+{- | not equal, treating null like an ordinary value
984+>>> printSQL $ true `isDistinctFrom` null_
985+(TRUE IS DISTINCT FROM NULL)
986+-}
987+isDistinctFrom
988+ :: Expression outer grp commons schemas params from (nullity ty)
989+ -> Expression outer grp commons schemas params from (nullity ty)
990+ -> Condition outer grp commons schemas params from
991+isDistinctFrom = unsafeBinaryOp "IS DISTINCT FROM"
992+
993+{- | equal, treating null like an ordinary value
994+>>> printSQL $ true `isNotDistinctFrom` null_
995+(TRUE IS NOT DISTINCT FROM NULL)
996+-}
997+isNotDistinctFrom
998+ :: Expression outer grp commons schemas params from (nullity ty)
999+ -> Expression outer grp commons schemas params from (nullity ty)
1000+ -> Condition outer grp commons schemas params from
1001+isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
1002+
1003+{- | is true
1004+>>> printSQL $ true & isTrue
1005+TRUE IS TRUE
1006+-}
1007+isTrue
1008+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1009+ -> Condition outer grp commons schemas params from
1010+isTrue b = UnsafeExpression $ renderSQL b <+> "IS TRUE"
1011+
1012+{- | is false or unknown
1013+>>> printSQL $ true & isNotTrue
1014+TRUE IS NOT TRUE
1015+-}
1016+isNotTrue
1017+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1018+ -> Condition outer grp commons schemas params from
1019+isNotTrue b = UnsafeExpression $ renderSQL b <+> "IS NOT TRUE"
1020+
1021+{- | is false
1022+>>> printSQL $ true & isFalse
1023+TRUE IS FALSE
1024+-}
1025+isFalse
1026+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1027+ -> Condition outer grp commons schemas params from
1028+isFalse b = UnsafeExpression $ renderSQL b <+> "IS FALSE"
1029+
1030+{- | is true or unknown
1031+>>> printSQL $ true & isNotFalse
1032+TRUE IS NOT FALSE
1033+-}
1034+isNotFalse
1035+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1036+ -> Condition outer grp commons schemas params from
1037+isNotFalse b = UnsafeExpression $ renderSQL b <+> "IS NOT FALSE"
1038+
1039+{- | is unknown
1040+>>> printSQL $ true & isUnknown
1041+TRUE IS UNKNOWN
1042+-}
1043+isUnknown
1044+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1045+ -> Condition outer grp commons schemas params from
1046+isUnknown b = UnsafeExpression $ renderSQL b <+> "IS UNKNOWN"
1047+
1048+{- | is true or false
1049+>>> printSQL $ true & isNotUnknown
1050+TRUE IS NOT UNKNOWN
1051+-}
1052+isNotUnknown
1053+ :: Expression outer grp commons schemas params from (nullity 'PGbool)
1054+ -> Condition outer grp commons schemas params from
1055+isNotUnknown b = UnsafeExpression $ renderSQL b <+> "IS NOT UNKNOWN"
1056+
9231057-- | >>> printSQL currentDate
9241058-- CURRENT_DATE
9251059currentDate
@@ -2424,3 +2558,7 @@ instance TimeOp 'PGtime 'PGinterval
24242558instance TimeOp 'PGtimetz 'PGinterval
24252559instance TimeOp 'PGinterval 'PGinterval
24262560instance TimeOp 'PGdate 'PGint4
2561+infixl 6 !+
2562+infixl 6 +!
2563+infixl 6 !-
2564+infixl 6 !-!