hasql-transaction 1.1.1.3 → 1.2
raw patch · 7 files changed
+30/−70 lines, 7 files
Files
- CHANGELOG.md +4/−0
- hasql-transaction.cabal +1/−1
- library/Hasql/Transaction/Private/SQL.hs +0/−8
- library/Hasql/Transaction/Private/Sessions.hs +12/−12
- library/Hasql/Transaction/Private/Statements.hs +9/−33
- library/Hasql/Transaction/Private/Transaction.hs +3/−3
- library/Hasql/Transaction/Sessions.hs +1/−13
CHANGELOG.md view
@@ -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)
hasql-transaction.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: hasql-transaction-version: 1.1.1.3+version: 1.2 category: Hasql, Database, PostgreSQL synopsis: Composable abstraction over retryable transactions for Hasql
library/Hasql/Transaction/Private/SQL.hs view
@@ -20,11 +20,3 @@ case mode of Write -> "READ WRITE" Read -> "READ ONLY"--declareCursor :: ByteString -> ByteString -> ByteString-declareCursor name sql =- D.toByteString- $ "DECLARE "- <> D.byteString name- <> " NO SCROLL CURSOR FOR "- <> D.byteString sql
library/Hasql/Transaction/Private/Sessions.hs view
@@ -10,32 +10,32 @@ 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
library/Hasql/Transaction/Private/Statements.hs view
@@ -7,38 +7,14 @@ import Hasql.Transaction.Private.Prelude 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--commitTransaction :: Bool -> A.Statement () ()-commitTransaction preparable =- A.Statement "COMMIT" B.noParams C.noResult preparable--abortTransaction :: Bool -> A.Statement () ()-abortTransaction preparable =- A.Statement "ABORT" B.noParams C.noResult preparable---- * Streaming--declareCursor :: ByteString -> ByteString -> B.Params a -> A.Statement a ()-declareCursor name sql encoder =- A.Statement (D.declareCursor name sql) encoder C.noResult False+beginTransaction :: IsolationLevel -> Mode -> A.Statement () ()+beginTransaction isolation mode =+ A.Statement (D.beginTransaction isolation mode) B.noParams C.noResult True -closeCursor :: A.Statement ByteString ()-closeCursor =- A.Statement "CLOSE $1" ((B.param . B.nonNullable) B.bytea) C.noResult True+commitTransaction :: A.Statement () ()+commitTransaction =+ A.Statement "COMMIT" B.noParams C.noResult True -fetchFromCursor :: (b -> a -> b) -> b -> C.Row a -> A.Statement (Int64, ByteString) b-fetchFromCursor step init rowDec =- A.Statement sql encoder decoder True- where- sql =- "FETCH FORWARD $1 FROM $2"- encoder =- (fst >$< (B.param . B.nonNullable) B.int8)- <> (snd >$< (B.param . B.nonNullable) B.bytea)- decoder =- C.foldlRows step init rowDec+abortTransaction :: A.Statement () ()+abortTransaction =+ A.Statement "ABORT" B.noParams C.noResult True
library/Hasql/Transaction/Private/Transaction.hs view
@@ -25,9 +25,9 @@ -- | -- 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,
library/Hasql/Transaction/Sessions.hs view
@@ -1,6 +1,5 @@ module Hasql.Transaction.Sessions ( transaction,- unpreparedTransaction, -- * Transaction settings C.Mode (..),@@ -8,7 +7,6 @@ ) 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 @@ {-# 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