hasql-pool 0.3 → 0.4
raw patch · 3 files changed
+37/−68 lines, 3 filesdep ~base-preludedep ~timePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base-prelude, time
API changes (from Hackage documentation)
- Hasql.Pool.Handle: data Handle s
- Hasql.Pool.Handle: session :: Handle s -> Session a -> IO (Either Error a)
- Hasql.Pool.Handle: type Error = Either ConnectionError Error
- Hasql.Pool.Handle: with :: Int -> NominalDiffTime -> Settings -> (forall s. Handle s -> IO a) -> IO a
+ Hasql.Pool: ConnectionError :: !ConnectionError -> UsageError
+ Hasql.Pool: SessionError :: !Error -> UsageError
+ Hasql.Pool: data UsageError
+ Hasql.Pool: instance GHC.Classes.Eq Hasql.Pool.UsageError
+ Hasql.Pool: instance GHC.Show.Show Hasql.Pool.UsageError
+ Hasql.Pool: type Settings = (Int, NominalDiffTime, Settings)
- Hasql.Pool: acquire :: Int -> NominalDiffTime -> Settings -> IO Pool
+ Hasql.Pool: acquire :: Settings -> IO Pool
- Hasql.Pool: use :: Pool -> (Connection -> IO a) -> IO (Either ConnectionError a)
+ Hasql.Pool: use :: Pool -> Session a -> IO (Either UsageError a)
Files
- hasql-pool.cabal +4/−5
- library/Hasql/Pool.hs +33/−7
- library/Hasql/Pool/Handle.hs +0/−56
hasql-pool.cabal view
@@ -1,7 +1,7 @@ name: hasql-pool version:- 0.3+ 0.4 category: Hasql, Database, PostgreSQL synopsis:@@ -38,20 +38,19 @@ library ghc-options: default-extensions:- Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, ImpredicativeTypes, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples+ Arrows, BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, TemplateHaskell, TupleSections, TypeFamilies, TypeOperators, UnboxedTuples default-language: Haskell2010 other-modules: Hasql.Pool.Prelude exposed-modules: Hasql.Pool- Hasql.Pool.Handle build-depends: -- resources: resource-pool >= 0.2 && < 0.3, -- database: hasql >= 0.19 && < 0.20, -- data:- time >= 1.4 && < 2,+ time >= 1.5 && < 2, -- general:- base-prelude >= 0.1.19 && < 0.2+ base-prelude >= 0.1.21 && < 0.2
library/Hasql/Pool.hs view
@@ -1,14 +1,17 @@ module Hasql.Pool ( Pool,+ Settings(..), acquire, release,+ UsageError(..), use, ) where import Hasql.Pool.Prelude import qualified Hasql.Connection+import qualified Hasql.Session import qualified Data.Pool @@ -18,10 +21,24 @@ Pool (Data.Pool.Pool (Either Hasql.Connection.ConnectionError Hasql.Connection.Connection)) -- |+-- Settings of the connection pool. Consist of:+-- +-- * Pool-size.+-- +-- * Timeout. +-- An amount of time for which an unused resource is kept open.+-- The smallest acceptable value is 0.5 seconds.+-- +-- * Connection settings.+-- +type Settings =+ (Int, NominalDiffTime, Hasql.Connection.Settings)++-- | -- Given the pool-size, timeout and connection settings -- create a connection-pool.-acquire :: Int -> NominalDiffTime -> Hasql.Connection.Settings -> IO Pool-acquire size timeout connectionSettings =+acquire :: Settings -> IO Pool+acquire (size, timeout, connectionSettings) = fmap Pool $ Data.Pool.createPool acquire release stripes timeout size where@@ -39,9 +56,18 @@ Data.Pool.destroyAllResources pool -- |--- Use a connection from the pool and return it to the pool, when finished.--- Exception-safe.-use :: Pool -> (Hasql.Connection.Connection -> IO a) -> IO (Either Hasql.Connection.ConnectionError a)-use (Pool pool) handler =- Data.Pool.withResource pool (traverse handler)+-- A union over the connection establishment error and the session error.+data UsageError =+ ConnectionError !Hasql.Connection.ConnectionError |+ SessionError !Hasql.Session.Error+ deriving (Show, Eq) +-- |+-- Use a connection from the pool to run a session and+-- return the connection to the pool, when finished.+use :: Pool -> Hasql.Session.Session a -> IO (Either UsageError a)+use (Pool pool) session =+ fmap (either (Left . ConnectionError) (either (Left . SessionError) Right)) $+ Data.Pool.withResource pool $+ traverse $ + Hasql.Session.run session
− library/Hasql/Pool/Handle.hs
@@ -1,56 +0,0 @@--- |--- Handle-pattern API.-module Hasql.Pool.Handle-(- Handle,- with,- -- * Usage- Error(..),- session,-)-where--import Hasql.Pool.Prelude hiding (Handle)-import qualified Hasql.Pool-import qualified Hasql.Connection-import qualified Hasql.Session----- |--- A temporary handle to the pool. -newtype Handle s =- Handle (forall a. Hasql.Session.Session a -> IO (Either Error a))---- |--- Given the pool-size, timeout and connection settings--- executes an IO function on a temporary handle,--- releasing it automatically afterwards.-with :: Int -> NominalDiffTime -> Hasql.Connection.Settings -> (forall s. Handle s -> IO a) -> IO a-with size timeout settings handler =- acquire >>= \pool -> use pool <* release pool- where- acquire =- Hasql.Pool.acquire size timeout settings- use pool =- handler $ Handle $ \session -> - fmap (either (Left . Left) (either (Left . Right) Right)) $- Hasql.Pool.use pool $- Hasql.Session.run session- release pool =- Hasql.Pool.release pool----- * Usage------------------------------ |--- Error of executing a session on a connection from the pool.-type Error =- Either Hasql.Connection.ConnectionError Hasql.Session.Error---- |--- Executes a session on a connection from the pool,--- using the provided temporary handle to it.-session :: Handle s -> Hasql.Session.Session a -> IO (Either Error a)-session (Handle runSession) session =- runSession session