packages feed

hasql-pool 0.1 → 0.3

raw patch · 3 files changed

+60/−4 lines, 3 filesdep ~hasqlPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: hasql

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

Files

hasql-pool.cabal view
@@ -1,7 +1,7 @@ name:   hasql-pool version:-  0.1+  0.3 category:   Hasql, Database, PostgreSQL synopsis:@@ -45,11 +45,12 @@     Hasql.Pool.Prelude   exposed-modules:     Hasql.Pool+    Hasql.Pool.Handle   build-depends:     -- resources:     resource-pool >= 0.2 && < 0.3,     -- database:-    hasql >= 0.15 && < 0.16,+    hasql >= 0.19 && < 0.20,     -- data:     time >= 1.4 && < 2,     -- general:
library/Hasql/Pool.hs view
@@ -9,7 +9,6 @@  import Hasql.Pool.Prelude import qualified Hasql.Connection-import qualified Hasql.Settings import qualified Data.Pool  @@ -21,7 +20,7 @@ -- | -- Given the pool-size, timeout and connection settings -- create a connection-pool.-acquire :: Int -> NominalDiffTime -> Hasql.Settings.Settings -> IO Pool+acquire :: Int -> NominalDiffTime -> Hasql.Connection.Settings -> IO Pool acquire size timeout connectionSettings =   fmap Pool $   Data.Pool.createPool acquire release stripes timeout size
+ library/Hasql/Pool/Handle.hs view
@@ -0,0 +1,56 @@+-- |+-- 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