persistent-postgresql 2.8.0 → 2.8.1
raw patch · 3 files changed
+43/−9 lines, 3 filesdep ~persistentPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: persistent
API changes (from Hackage documentation)
Files
- ChangeLog.md +4/−0
- Database/Persist/Postgresql.hs +37/−7
- persistent-postgresql.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+## 2.8.1++* Implemented `connPutManySql` to utilize batched `putMany`. [#770](https://github.com/yesodweb/persistent/pull/770)+ ## 2.8.0 * Switch from `MonadBaseControl` to `MonadUnliftIO`
Database/Persist/Postgresql.hs view
@@ -31,7 +31,7 @@ ) where import Database.Persist.Sql-import Database.Persist.Sql.Util (dbIdColumnsEsc)+import Database.Persist.Sql.Util (dbIdColumnsEsc, commaSeparated, parenWrapped) import Database.Persist.Sql.Types.Internal (mkPersistBackend) import Data.Fixed (Pico) @@ -123,7 +123,7 @@ -- -- @since 2.6.2 withPostgresqlPoolWithVersion :: (MonadUnliftIO m, MonadLogger m, IsSqlBackend backend)- => (PG.Connection -> IO (Maybe Double)) + => (PG.Connection -> IO (Maybe Double)) -- ^ action to perform to get the server version -> ConnectionString -- ^ Connection string to the database.@@ -225,9 +225,10 @@ -- | Choose upsert sql generation function based on postgresql version. -- PostgreSQL version >= 9.5 supports native upsert feature, -- so depending upon that we have to choose how the sql query is generated.-upsertFunction :: Double -> Maybe (EntityDef -> Text -> Text)-upsertFunction version = if (version >= 9.5)- then Just upsertSql'+-- upsertFunction :: Double -> Maybe (EntityDef -> Text -> Text)+upsertFunction :: a -> Double -> Maybe a+upsertFunction f version = if (version >= 9.5)+ then Just f else Nothing @@ -248,7 +249,8 @@ , connStmtMap = smap , connInsertSql = insertSql' , connInsertManySql = Just insertManySql'- , connUpsertSql = maybe Nothing upsertFunction serverVersion+ , connUpsertSql = serverVersion >>= upsertFunction upsertSql'+ , connPutManySql = serverVersion >>= upsertFunction putManySql , connClose = PG.close conn , connMigrateSql = migrate' , connBegin = const $ PG.begin conn@@ -328,7 +330,7 @@ , ") VALUES (" , T.intercalate "),(" $ replicate (length valss) $ T.intercalate "," $ map (const "?") (entityFields ent) , ") RETURNING "- , T.intercalate ", " $ dbIdColumnsEsc escape ent+ , commaSeparated $ dbIdColumnsEsc escape ent ] in ISRSingle sql @@ -1171,6 +1173,7 @@ connInsertManySql = Nothing, connInsertSql = undefined, connUpsertSql = Nothing,+ connPutManySql = Nothing, connStmtMap = smap, connClose = undefined, connMigrateSql = mockMigrate,@@ -1186,6 +1189,33 @@ result = runReaderT $ runWriterT $ runWriterT mig resp <- result sqlbackend mapM_ T.putStrLn $ map snd $ snd resp++putManySql :: EntityDef -> Int -> Text+putManySql entityDef' numRecords+ | numRecords > 0 = q+ | otherwise = error "putManySql: numRecords MUST be greater than 0!"+ where+ tableName' = escape . entityDB $ entityDef'+ fieldDbToText = escape . fieldDB+ entityFieldNames = map fieldDbToText (entityFields entityDef')+ recordPlaceholders= parenWrapped . commaSeparated+ $ map (const "?") (entityFields entityDef')+ mkAssignment n = T.concat [n, "=EXCLUDED.", n]+ fieldSets = map (mkAssignment . fieldDbToText) (entityFields entityDef')+ uniqueFields' = concat $ map (\x -> map escape (map snd $ uniqueFields x)) (entityUniques entityDef')+ q = T.concat+ [ "INSERT INTO "+ , tableName'+ , " ("+ , commaSeparated entityFieldNames+ , ") "+ , " VALUES "+ , commaSeparated (replicate numRecords recordPlaceholders)+ , " ON CONFLICT ("+ , commaSeparated uniqueFields'+ , ") DO UPDATE SET "+ , commaSeparated fieldSets+ ] -- | Enable a Postgres extension. See https://www.postgresql.org/docs/10/static/contrib.html -- for a list.
persistent-postgresql.cabal view
@@ -1,5 +1,5 @@ name: persistent-postgresql-version: 2.8.0+version: 2.8.1 license: MIT license-file: LICENSE author: Felipe Lessa, Michael Snoyman <michael@snoyman.com>@@ -19,7 +19,7 @@ , transformers >= 0.2.1 , postgresql-simple >= 0.4.0 && < 0.6 , postgresql-libpq >= 0.6.1 && < 0.10- , persistent >= 2.8.0 && < 3+ , persistent >= 2.8.1 && < 3 , containers >= 0.2 , bytestring >= 0.9 , text >= 0.7