add withConnectionCommit.

This commit is contained in:
Kei Hibino 2016-09-09 14:34:32 +09:00
parent 9d2c52bec2
commit 94f1446bd7

View File

@ -14,6 +14,7 @@
module Database.HDBC.Session (
-- * Bracketed session
-- $bracketedSession
withConnectionCommit,
withConnectionIO, withConnectionIO',
withConnection,
@ -79,6 +80,18 @@ withConnectionIO :: IConnection conn
-> IO a -- ^ Result transaction action
withConnectionIO = withConnection bracket id
-- | Same as 'withConnectionIO' other than issuing commit at the end of transaction body.
-- In other words, the transaction with no exception is committed.
withConnectionCommit :: IConnection conn
=> IO conn -- ^ Connect action
-> (conn -> IO a) -- ^ Transaction body
-> IO a -- ^ Result transaction action
withConnectionCommit conn body =
withConnectionIO conn $ \c -> do
x <- body c
HDBC.commit c
return x
-- | Same as 'withConnectionIO' other than wrapping transaction body in 'handleSqlError''.
withConnectionIO' :: IConnection conn
=> IO conn -- ^ Connect action