Skip to content

Commit

Permalink
Use resourcet-pool (#1163)
Browse files Browse the repository at this point in the history
* Use resourcet-pool

* Bump version

Co-authored-by: Matt Parsons <[email protected]>
  • Loading branch information
brandonchinn178 and parsonsmatt authored Jan 6, 2021
1 parent f69716d commit f82154f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
1 change: 1 addition & 0 deletions persistent/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* [#1162](https://github.com/yesodweb/persistent/pull/1162)
* Replace `askLogFunc` with `askLoggerIO`
* Decomposed `HaskellName` into `ConstraintNameHS`, `EntityNameHS`, `FieldNameHS`. Decomposed `DBName` into `ConstraintNameDB`, `EntityNameDB`, `FieldNameDB` respectively. [#1174](https://github.com/yesodweb/persistent/pull/1174)
* Use `resourcet-pool` to break out some `Data.Pool` logic [#1163](https://github.com/yesodweb/persistent/pull/1163)

## 2.11.0.2
* Fix a bug where an empty entity definition would break parsing of `EntityDef`s. [#1176](https://github.com/yesodweb/persistent/issues/1176)
Expand Down
11 changes: 2 additions & 9 deletions persistent/Database/Persist/Sql/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import Data.Acquire (Acquire, ReleaseType(..), mkAcquireType, with)
import Data.IORef (readIORef)
import Data.Pool (Pool, LocalPool)
import Data.Pool as P
import Data.Pool.Acquire (poolToAcquire)
import qualified Data.Map as Map
import qualified Data.Text as T
import System.Timeout (timeout)
Expand All @@ -34,15 +35,7 @@ unsafeAcquireSqlConnFromPool
:: forall backend m
. (MonadReader (Pool backend) m, BackendCompatible SqlBackend backend)
=> m (Acquire backend)
unsafeAcquireSqlConnFromPool = do
pool <- MonadReader.ask

let freeConn :: (backend, LocalPool backend) -> ReleaseType -> IO ()
freeConn (res, localPool) relType = case relType of
ReleaseException -> P.destroyResource pool localPool res
_ -> P.putResource localPool res

return $ fst <$> mkAcquireType (P.takeResource pool) freeConn
unsafeAcquireSqlConnFromPool = MonadReader.asks poolToAcquire


-- | The returned 'Acquire' gets a connection from the pool, starts a new
Expand Down
1 change: 1 addition & 0 deletions persistent/persistent.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ library
, path-pieces >= 0.2
, resource-pool >= 0.2.3
, resourcet >= 1.1.10
, resourcet-pool
, scientific
, silently
, text >= 1.2
Expand Down
3 changes: 3 additions & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ packages:
- ./persistent-postgresql
- ./persistent-redis
- ./persistent-qq

extra-deps:
- resourcet-pool-0.1.0.0

0 comments on commit f82154f

Please sign in to comment.