on dev help sign in
simplify subAny/subAll
7e3913dEitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/Query.hs+6−16
@@ -107,7 +107,6 @@ import Data.Word
107import Generics.SOP hiding (from)
107import Generics.SOP hiding (from)
108import GHC.TypeLits
108import GHC.TypeLits
109
109
110−import qualified Data.ByteString as ByteString
111import qualified GHC.Generics as GHC
110import qualified GHC.Generics as GHC
112
111
113import Squeal.PostgreSQL.Expression
112import Squeal.PostgreSQL.Expression
@@ -1091,21 +1090,15 @@ The result is `null_` if no comparison with a subquery row returns `false`,
1091and at least one comparison returns `null_`.
1090and at least one comparison returns `null_`.
1092
1091
1093>>> printSQL $ subAll true (.==) (values_ (true `as` #foo))
1092>>> printSQL $ subAll true (.==) (values_ (true `as` #foo))
1094−TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo"))
1093+(TRUE = ALL (SELECT * FROM (VALUES (TRUE)) AS t ("foo")))
1095-}
1094-}
1096subAll
1095subAll
1097 :: Expression outer grp commons schemas params from ty1 -- ^ expression
1096 :: Expression outer grp commons schemas params from ty1 -- ^ expression
1098 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1097 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1099 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1098 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1100 -> Condition outer grp commons schemas params from
1099 -> Condition outer grp commons schemas params from
1101−subAll expr (?) qry = UnsafeExpression $
1100+subAll expr (?) qry = expr ?
1102− renderSQL expr <> op <> "ALL" <+> parenthesized (renderSQL qry)
1101+ (UnsafeExpression $ "ALL" <+> parenthesized (renderSQL qry))
1103− where
1104− nil = UnsafeExpression ""
1105− op = ByteString.init
1106− . ByteString.tail
1107− . renderSQL
1108− $ nil ? nil
1109
1102
1110{- |
1103{- |
1111The right-hand side is a parenthesized subquery, which must return exactly one column.
1104The right-hand side is a parenthesized subquery, which must return exactly one column.
@@ -1115,18 +1108,15 @@ if any `true` result is obtained. The result is `false` if no true result is fou
1115(including the case where the subquery returns no rows).
1108(including the case where the subquery returns no rows).
1116
1109
1117>>> printSQL $ subAll "foo" like (values_ ("foobar" `as` #foo))
1110>>> printSQL $ subAll "foo" like (values_ ("foobar" `as` #foo))
1118−E'foo' LIKE ALL (SELECT * FROM (VALUES (E'foobar')) AS t ("foo"))
1111+(E'foo' LIKE ALL (SELECT * FROM (VALUES (E'foobar')) AS t ("foo")))
1119-}
1112-}
1120subAny
1113subAny
1121 :: Expression outer grp commons schemas params from ty1 -- ^ expression
1114 :: Expression outer grp commons schemas params from ty1 -- ^ expression
1122 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1115 -> Operator ty1 ty2 ('Null 'PGbool) -- ^ operator
1123 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1116 -> Query (Join outer from) commons schemas params '[col ::: ty2] -- ^ subquery
1124 -> Condition outer grp commons schemas params from
1117 -> Condition outer grp commons schemas params from
1125−subAny expr (?) qry = UnsafeExpression $
1118+subAny expr (?) qry = expr ?
1126− renderSQL expr <+> renderSQL (nil ? nil) <+> "ANY"
1127− <+> parenthesized (renderSQL qry)
1119+ (UnsafeExpression $ "ANY" <+> parenthesized (renderSQL qry))
1128− where
1129− nil = UnsafeExpression ""
1130
1120
1131{-
1121{-
1132The result is `true` if the left-hand expression's result is equal
1122The result is `true` if the left-hand expression's result is equal