hpqtypes-extras 1.10.2.1 → 1.10.3.0
raw patch · 3 files changed
+27/−9 lines, 3 filesdep ~base16-bytestringPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base16-bytestring
API changes (from Hackage documentation)
Files
CHANGELOG.md view
@@ -1,3 +1,6 @@+# hpqtypes-extra-1.10.3.0 (2020-11-16)+* Include LIMIT clause in UNION subqueries of the select+ # hpqtypes-extras-1.10.2.1 (2020-05-05) * Add support for GHC 8.10
hpqtypes-extras.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: hpqtypes-extras-version: 1.10.2.1+version: 1.10.3.0 synopsis: Extra utilities for hpqtypes library description: The following extras for hpqtypes library: .@@ -64,7 +64,7 @@ , monad-control >= 1.0 && < 1.1 , semigroups >= 0.16 && < 0.20 , text-show >= 3.7 && < 3.9- , log-base >= 0.7 && < 0.9+ , log-base >= 0.7 && < 0.10 , safe >= 0.3 && < 0.4 default-language: Haskell2010
src/Database/PostgreSQL/PQTypes/SQL/Builder.hs view
@@ -431,21 +431,36 @@ toSQLCommand cmd = smconcat [ emitClausesSepComma "WITH" $ map (\(name,command) -> name <+> "AS" <+> parenthesize command) (sqlSelectWith cmd)- , "SELECT" <+> (if sqlSelectDistinct cmd then "DISTINCT" else mempty)- , sqlConcatComma (sqlSelectResult cmd)- , emitClause "FROM" (sqlSelectFrom cmd)- , emitClausesSep "WHERE" "AND" (map toSQLCommand $ sqlSelectWhere cmd)- , emitClausesSep "UNION" "UNION" (sqlSelectUnion cmd)+ , if hasUnion+ then emitClausesSep "" "UNION" (mainSelectClause : sqlSelectUnion cmd)+ else mainSelectClause , emitClausesSepComma "GROUP BY" (sqlSelectGroupBy cmd) , emitClausesSep "HAVING" "AND" (sqlSelectHaving cmd)- , emitClausesSepComma "ORDER BY" (sqlSelectOrderBy cmd)+ , orderByClause , if sqlSelectOffset cmd > 0 then unsafeSQL ("OFFSET " ++ show (sqlSelectOffset cmd)) else "" , if sqlSelectLimit cmd >= 0- then unsafeSQL ("LIMIT " ++ show (sqlSelectLimit cmd))+ then limitClause else "" ]+ where+ mainSelectClause = smconcat+ [ "SELECT" <+> (if sqlSelectDistinct cmd then "DISTINCT" else mempty)+ , sqlConcatComma (sqlSelectResult cmd)+ , emitClause "FROM" (sqlSelectFrom cmd)+ , emitClausesSep "WHERE" "AND" (map toSQLCommand $ sqlSelectWhere cmd)+ -- If there's a union, the result is sorted and has a limit, applying+ -- the order and limit to the main subquery won't reduce the overall+ -- query result, but might reduce its processing time.+ , if hasUnion && not (null $ sqlSelectOrderBy cmd) && sqlSelectLimit cmd >= 0+ then smconcat [orderByClause, limitClause]+ else ""+ ]++ hasUnion = not . null $ sqlSelectUnion cmd+ orderByClause = emitClausesSepComma "ORDER BY" $ sqlSelectOrderBy cmd+ limitClause = unsafeSQL $ "LIMIT" <+> show (sqlSelectLimit cmd) instance Sqlable SqlInsert where toSQLCommand cmd =