diff --git a/CHANGELOG.md b/CHANGELOG.md index 558d447..ea14246 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.2 + +- Removed the `unpreparedTransaction` session because the same effects can now be achieved via the connection settings in Hasql + # 1.1 - Add automatic retry on deadlock errors (code 40P01) diff --git a/library/Hasql/Transaction/Private/Sessions.hs b/library/Hasql/Transaction/Private/Sessions.hs index e6ff8db..5dd52db 100644 --- a/library/Hasql/Transaction/Private/Sessions.hs +++ b/library/Hasql/Transaction/Private/Sessions.hs @@ -10,32 +10,32 @@ We may want to do one transaction retry in case of the 23505 error, and fail if an identical error is seen. -} -inRetryingTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Bool -> Session a -inRetryingTransaction level mode session preparable = +inRetryingTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Session a +inRetryingTransaction level mode session = fix $ \retry -> do - attemptRes <- tryTransaction level mode session preparable + attemptRes <- tryTransaction level mode session case attemptRes of Just a -> return a Nothing -> retry -tryTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Bool -> Session (Maybe a) -tryTransaction level mode body preparable = do - statement () (Statements.beginTransaction level mode preparable) +tryTransaction :: IsolationLevel -> Mode -> Session (a, Bool) -> Session (Maybe a) +tryTransaction level mode body = do + statement () (Statements.beginTransaction level mode) bodyRes <- catchError (fmap Just body) $ \error -> do - statement () (Statements.abortTransaction preparable) + statement () Statements.abortTransaction handleTransactionError error $ return Nothing case bodyRes of - Just (res, commit) -> catchError (commitOrAbort commit preparable $> Just res) $ \error -> do + Just (res, commit) -> catchError (commitOrAbort commit $> Just res) $ \error -> do handleTransactionError error $ return Nothing Nothing -> return Nothing -commitOrAbort :: Bool -> Bool -> Session () -commitOrAbort commit preparable = +commitOrAbort :: Bool -> Session () +commitOrAbort commit = if commit - then statement () (Statements.commitTransaction preparable) - else statement () (Statements.abortTransaction preparable) + then statement () Statements.commitTransaction + else statement () Statements.abortTransaction handleTransactionError :: SessionError -> Session a -> Session a handleTransactionError error onTransactionError = case error of diff --git a/library/Hasql/Transaction/Private/Statements.hs b/library/Hasql/Transaction/Private/Statements.hs index 6a55663..bacc134 100644 --- a/library/Hasql/Transaction/Private/Statements.hs +++ b/library/Hasql/Transaction/Private/Statements.hs @@ -9,17 +9,17 @@ import Hasql.Transaction.Private.SQL qualified as D -- * Transactions -beginTransaction :: IsolationLevel -> Mode -> Bool -> A.Statement () () -beginTransaction isolation mode preparable = - A.Statement (D.beginTransaction isolation mode) B.noParams C.noResult preparable +beginTransaction :: IsolationLevel -> Mode -> A.Statement () () +beginTransaction isolation mode = + A.Statement (D.beginTransaction isolation mode) B.noParams C.noResult True -commitTransaction :: Bool -> A.Statement () () -commitTransaction preparable = - A.Statement "COMMIT" B.noParams C.noResult preparable +commitTransaction :: A.Statement () () +commitTransaction = + A.Statement "COMMIT" B.noParams C.noResult True -abortTransaction :: Bool -> A.Statement () () -abortTransaction preparable = - A.Statement "ABORT" B.noParams C.noResult preparable +abortTransaction :: A.Statement () () +abortTransaction = + A.Statement "ABORT" B.noParams C.noResult True -- * Streaming diff --git a/library/Hasql/Transaction/Private/Transaction.hs b/library/Hasql/Transaction/Private/Transaction.hs index 7f15e2c..b3b10a6 100644 --- a/library/Hasql/Transaction/Private/Transaction.hs +++ b/library/Hasql/Transaction/Private/Transaction.hs @@ -25,9 +25,9 @@ instance (Monoid a) => Monoid (Transaction a) where -- | -- Execute the transaction using the provided isolation level and mode. {-# INLINE run #-} -run :: Transaction a -> IsolationLevel -> Mode -> Bool -> B.Session a -run (Transaction session) isolation mode preparable = - D.inRetryingTransaction isolation mode (runStateT session True) preparable +run :: Transaction a -> IsolationLevel -> Mode -> B.Session a +run (Transaction session) isolation mode = + D.inRetryingTransaction isolation mode (runStateT session True) -- | -- Possibly a multi-statement query, diff --git a/library/Hasql/Transaction/Sessions.hs b/library/Hasql/Transaction/Sessions.hs index 2b2dc56..35383eb 100644 --- a/library/Hasql/Transaction/Sessions.hs +++ b/library/Hasql/Transaction/Sessions.hs @@ -1,6 +1,5 @@ module Hasql.Transaction.Sessions ( transaction, - unpreparedTransaction, -- * Transaction settings C.Mode (..), @@ -8,7 +7,6 @@ module Hasql.Transaction.Sessions ) where -import Data.Bool import Hasql.Session qualified as B import Hasql.Transaction.Config qualified as C import Hasql.Transaction.Private.Transaction qualified as A @@ -18,14 +16,4 @@ import Hasql.Transaction.Private.Transaction qualified as A {-# INLINE transaction #-} transaction :: C.IsolationLevel -> C.Mode -> A.Transaction a -> B.Session a transaction isolation mode transaction = - 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 + A.run transaction isolation mode