Skip to content

Commit f43490c

Browse files
committed
haddock
1 parent a353cdd commit f43490c

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

src/Database/PostgreSQL/PQTypes/Internal/State.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ data ConnectionState cdata
3939
| Acquired !IsolationLevel !Permissions !Connection !cdata
4040
| Finalized
4141

42+
-- Note: initConnectionState and finalizeConnectionState are invoked inside
43+
-- bracket and run with asynchronous exceptions softly masked. However, both of
44+
-- them may run queries that start/finish a transaction. Running queries is a
45+
-- blocking (and thus interruptible) operation, but if these queries are
46+
-- interrupted with an asynchronous exception, then a connection is leaked, so
47+
-- they need to be run with asynchronous exceptions hard masked with
48+
-- uninterruptibleMask.
49+
4250
initConnectionState
4351
:: MonadBase IO m
4452
=> InternalConnectionSource m cdata

src/Database/PostgreSQL/PQTypes/Transaction.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ rollback = uninterruptibleMask_ $ do
9191
runSQL_ "ROLLBACK"
9292
begin
9393

94+
-- | Run a block of code without an open transaction.
95+
--
96+
-- This function is unsafe in the 'AcquireAndHold' mode because running it
97+
-- commits the transaction in progress, so the atomicity guarantee is lost.
9498
unsafeWithoutTransaction
9599
:: (HasCallStack, MonadDB m, MonadMask m)
96100
=> m a

src/Database/PostgreSQL/PQTypes/Transaction/Settings.hs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,17 @@ data IsolationLevel = DefaultLevel | ReadCommitted | RepeatableRead | Serializab
4444
data Permissions = DefaultPermissions | ReadOnly | ReadWrite
4545
deriving (Eq, Ord, Show)
4646

47+
-- | Acquisition mode of a database connection.
4748
data ConnectionAcquisitionMode
4849
= AcquireOnDemand
50+
-- ^ Acquire a connection on demand, i.e. only when a query needs to be
51+
-- run. This mode allows you to have a 'MonadDB' constraint in scope without
52+
-- holding onto connections and keeping transactions open, but allows only
53+
-- execution of read only queries.
4954
| AcquireAndHold !IsolationLevel !Permissions
55+
-- ^ Acquire a connection, start a transaction with a given isolation level
56+
-- and permissions and hold onto it for the duration of a 'MonadDB' constraint
57+
-- in scope.
5058
deriving (Eq, Ord, Show)
5159

5260
-- | Default transaction settings.

0 commit comments

Comments
 (0)