File tree Expand file tree Collapse file tree 3 files changed +20
-0
lines changed
src/Database/PostgreSQL/PQTypes Expand file tree Collapse file tree 3 files changed +20
-0
lines changed Original file line number Diff line number Diff 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+
4250initConnectionState
4351 :: MonadBase IO m
4452 => InternalConnectionSource m cdata
Original file line number Diff line number Diff 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.
9498unsafeWithoutTransaction
9599 :: (HasCallStack , MonadDB m , MonadMask m )
96100 => m a
Original file line number Diff line number Diff line change @@ -44,9 +44,17 @@ data IsolationLevel = DefaultLevel | ReadCommitted | RepeatableRead | Serializab
4444data Permissions = DefaultPermissions | ReadOnly | ReadWrite
4545 deriving (Eq , Ord , Show )
4646
47+ -- | Acquisition mode of a database connection.
4748data 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.
You can’t perform that action at this time.
0 commit comments