Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Remove pool-conduit dep from persistent
Browse files Browse the repository at this point in the history
  • Loading branch information
snoyberg committed Mar 21, 2014
1 parent d73dc04 commit 74ea262
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion persistent/Database/Persist/Sql.hs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module Database.Persist.Sql
import Database.Persist
import Database.Persist.Sql.Types
import Database.Persist.Sql.Class
import Database.Persist.Sql.Run
import Database.Persist.Sql.Run hiding (withResourceTimeout)
import Database.Persist.Sql.Raw
import Database.Persist.Sql.Migration
import Database.Persist.Sql.Internal
Expand Down
24 changes: 23 additions & 1 deletion persistent/Database/Persist/Sql/Run.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ module Database.Persist.Sql.Run where

import Database.Persist.Sql.Types
import Database.Persist.Sql.Raw
import Data.Conduit.Pool
import Data.Pool as P
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Resource
import Control.Monad.Logger
import Control.Monad.Base
import Control.Exception.Lifted (onException)
import Control.Monad.IO.Class
import Control.Exception.Lifted (bracket)
import Control.Exception (mask)
import System.Timeout (timeout)
import Control.Monad.Trans.Control (control)
import Data.IORef (readIORef)
import qualified Data.Map as Map
import Control.Exception.Lifted (throwIO)
import Control.Monad (liftM)

-- | Get a connection from the pool, run the given action, and then return the
-- connection to the pool.
Expand All @@ -22,6 +26,24 @@ runSqlPool r pconn = do
mres <- withResourceTimeout 2000000 pconn $ runSqlConn r
maybe (throwIO Couldn'tGetSQLConnection) return mres

withResourceTimeout
:: (MonadBaseControl IO m)
=> Int -- ^ Timeout period in microseconds
-> P.Pool a
-> (a -> m b)
-> m (Maybe b)
{-# SPECIALIZE withResourceTimeout :: Int -> P.Pool a -> (a -> IO b) -> IO (Maybe b) #-}
withResourceTimeout ms pool act = control $ \runInIO -> mask $ \restore -> do
mres <- timeout ms $ P.takeResource pool
case mres of
Nothing -> runInIO $ return Nothing
Just (resource, local) -> do
ret <- restore (runInIO (liftM Just $ act resource)) `onException`
P.destroyResource pool local resource
P.putResource local resource
return ret
{-# INLINABLE withResourceTimeout #-}

runSqlConn :: MonadBaseControl IO m => SqlPersistT m a -> Connection -> m a
runSqlConn (SqlPersistT r) conn = do
let getter = getStmtConn conn
Expand Down
2 changes: 1 addition & 1 deletion persistent/Database/Persist/Sql/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import Data.IORef (IORef)
import Data.Map (Map)
import Data.Int (Int64)
import Data.Conduit (Source)
import Data.Conduit.Pool (Pool)
import Data.Pool (Pool)
import Web.PathPieces
import Control.Exception (throw)
import qualified Data.Text.Read
Expand Down
4 changes: 2 additions & 2 deletions persistent/persistent.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: persistent
version: 1.3.0.3
version: 1.3.0.4
license: MIT
license-file: LICENSE
author: Michael Snoyman <[email protected]>
Expand Down Expand Up @@ -31,7 +31,6 @@ library
, resourcet >= 0.4
, monad-control >= 0.3
, lifted-base >= 0.1
, pool-conduit >= 0.1.2
, path-pieces >= 0.1
, aeson >= 0.5
, monad-logger >= 0.3
Expand All @@ -45,6 +44,7 @@ library
, blaze-markup >= 0.5.1
, silently
, scientific
, resource-pool

exposed-modules: Database.Persist
Database.Persist.Quasi
Expand Down

0 comments on commit 74ea262

Please sign in to comment.