hasql-transaction 1.0.0.2 → 1.0.1
raw patch · 5 files changed
+37/−25 lines, 5 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
+ Hasql.Transaction.Sessions: unpreparedTransaction :: IsolationLevel -> Mode -> Transaction a -> Session a
Files
- hasql-transaction.cabal +1/−1
- library/Hasql/Transaction/Private/Sessions.hs +11/−11
- library/Hasql/Transaction/Private/Statements.hs +9/−9
- library/Hasql/Transaction/Private/Transaction.hs +3/−3
- library/Hasql/Transaction/Sessions.hs +13/−1
hasql-transaction.cabal view
@@ -1,5 +1,5 @@ name: hasql-transaction-version: 1.0.0.2+version: 1.0.1 category: Hasql, Database, PostgreSQL synopsis: Composable abstraction over retryable transactions for Hasql homepage: https://github.com/nikita-volkov/hasql-transaction
library/Hasql/Transaction/Private/Sessions.hs view
@@ -12,31 +12,31 @@ do one transaction retry in case of the 23505 error, and fail if an identical error is seen. -}-inRetryingTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Session a-inRetryingTransaction level mode session =+inRetryingTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Bool -> Session a+inRetryingTransaction level mode session preparable = fix $ \ retry -> do- attemptRes <- tryTransaction level mode session+ attemptRes <- tryTransaction level mode session preparable case attemptRes of Just a -> return a Nothing -> retry -tryTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Session (Maybe a)-tryTransaction level mode body = do+tryTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Bool -> Session (Maybe a)+tryTransaction level mode body preparable = do - statement () (Statements.beginTransaction level mode)+ statement () (Statements.beginTransaction level mode preparable) bodyRes <- catchError (fmap Just body) $ \ error -> do- statement () Statements.abortTransaction+ statement () (Statements.abortTransaction preparable) handleTransactionError error $ return Nothing case bodyRes of- Just (res, commit) -> catchError (commitOrAbort commit $> Just res) $ \ error -> do+ Just (res, commit) -> catchError (commitOrAbort commit preparable $> Just res) $ \ error -> do handleTransactionError error $ return Nothing Nothing -> return Nothing -commitOrAbort commit = if commit- then statement () Statements.commitTransaction- else statement () Statements.abortTransaction+commitOrAbort commit preparable = if commit+ then statement () (Statements.commitTransaction preparable)+ else statement () (Statements.abortTransaction preparable) handleTransactionError error onTransactionError = case error of QueryError _ _ (ResultError (ServerError "40001" _ _ _)) -> onTransactionError
library/Hasql/Transaction/Private/Statements.hs view
@@ -12,17 +12,17 @@ -- * Transactions ------------------------- -beginTransaction :: IsolationLevel -> Mode -> A.Statement () ()-beginTransaction isolation mode =- A.Statement (D.beginTransaction isolation mode) B.noParams C.noResult True+beginTransaction :: IsolationLevel -> Mode -> Bool -> A.Statement () ()+beginTransaction isolation mode preparable =+ A.Statement (D.beginTransaction isolation mode) B.noParams C.noResult preparable -commitTransaction :: A.Statement () ()-commitTransaction =- A.Statement "COMMIT" B.noParams C.noResult True+commitTransaction :: Bool -> A.Statement () ()+commitTransaction preparable =+ A.Statement "COMMIT" B.noParams C.noResult preparable -abortTransaction :: A.Statement () ()-abortTransaction =- A.Statement "ABORT" B.noParams C.noResult True+abortTransaction :: Bool -> A.Statement () ()+abortTransaction preparable =+ A.Statement "ABORT" B.noParams C.noResult preparable -- * Streaming
library/Hasql/Transaction/Private/Transaction.hs view
@@ -29,9 +29,9 @@ -- | -- Execute the transaction using the provided isolation level and mode. {-# INLINE run #-}-run :: Transaction a -> IsolationLevel -> Mode -> B.Session a-run (Transaction session) isolation mode =- D.inRetryingTransaction isolation mode (runStateT session True)+run :: Transaction a -> IsolationLevel -> Mode -> Bool -> B.Session a+run (Transaction session) isolation mode preparable =+ D.inRetryingTransaction isolation mode (runStateT session True) preparable -- | -- Possibly a multi-statement query,
library/Hasql/Transaction/Sessions.hs view
@@ -1,12 +1,14 @@ module Hasql.Transaction.Sessions ( transaction,+ unpreparedTransaction, -- * Transaction settings C.Mode(..), C.IsolationLevel(..), ) where +import Data.Bool import qualified Hasql.Transaction.Private.Transaction as A import qualified Hasql.Session as B import qualified Hasql.Transaction.Private.Model as C@@ -17,4 +19,14 @@ {-# INLINE transaction #-} transaction :: C.IsolationLevel -> C.Mode -> A.Transaction a -> B.Session a transaction isolation mode transaction =- A.run transaction isolation mode+ A.run transaction isolation mode True++-- |+-- Execute the transaction using the provided isolation level and mode,+-- and specifying that the generated BEGIN, COMMIT and ABORT statements should not be prepared.+--+-- Helps with transaction pooling due to its incompatibility with prepared statements.+{-# INLINE unpreparedTransaction #-}+unpreparedTransaction :: C.IsolationLevel -> C.Mode -> A.Transaction a -> B.Session a+unpreparedTransaction isolation mode transaction =+ A.run transaction isolation mode False