persistent-postgresql 2.1.6 → 2.2
raw patch · 3 files changed
+22/−2 lines, 3 filesdep ~persistent
Dependency ranges changed: persistent
Files
- ChangeLog.md +4/−0
- Database/Persist/Postgresql.hs +16/−0
- persistent-postgresql.cabal +2/−2
ChangeLog.md view
@@ -1,3 +1,7 @@+## 2.2++* Optimize the `insertMany` function to insert all rows and retrieve their keys in one SQL query. [#407](https://github.com/yesodweb/persistent/pull/407)+ ## 2.1.6 * Postgresql exceptions [#353](https://github.com/yesodweb/persistent/issues/353)
Database/Persist/Postgresql.hs view
@@ -147,6 +147,7 @@ { connPrepare = prepare' conn , connStmtMap = smap , connInsertSql = insertSql'+ , connInsertManySql = Just insertManySql' , connClose = PG.close conn , connMigrateSql = migrate' , connBegin = const $ PG.begin conn@@ -187,6 +188,21 @@ in case entityPrimary ent of Just _pdef -> ISRManyKeys sql vals Nothing -> ISRSingle (sql <> " RETURNING " <> escape (fieldDB (entityId ent)))++-- | SQL for inserting multiple rows at once and returning their primary keys.+insertManySql' :: EntityDef -> [[PersistValue]] -> InsertSqlResult+insertManySql' ent valss =+ let sql = T.concat+ [ "INSERT INTO "+ , escape (entityDB ent)+ , "("+ , T.intercalate "," $ map (escape . fieldDB) $ entityFields ent+ , ") VALUES ("+ , T.intercalate "),(" $ replicate (length valss) $ T.intercalate "," $ map (const "?") (entityFields ent)+ , ") RETURNING "+ , T.intercalate ", " $ dbIdColumnsEsc escape ent+ ]+ in ISRSingle sql execute' :: PG.Connection -> PG.Query -> [PersistValue] -> IO Int64 execute' conn query vals = PG.execute conn query (map P vals)
persistent-postgresql.cabal view
@@ -1,5 +1,5 @@ name: persistent-postgresql-version: 2.1.6+version: 2.2 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.5 , postgresql-libpq >= 0.6.1 && < 0.10- , persistent >= 2.1.5 && < 3+ , persistent >= 2.2 && < 3 , containers >= 0.2 , bytestring >= 0.9 , text >= 0.7