@@ -21,6 +21,8 @@ module Squeal.PostgreSQL.Transaction
21 transactionally
21 transactionally
22 , transactionally_
22 , transactionally_
23 , transactionallyRetry
23 , transactionallyRetry
26 , rollback
28 , rollback
@@ -94,6 +96,28 @@ transactionallyRetry mode tx = mask $ \restore ->
94 throwIO err
96 throwIO err
95 Right x -> return x
97 Right x -> return x
99+{- | Run a computation `ephemerally`;
100+First `begin`, then run the computation, `rollback` and `return`
104+ :: (MonadIO tx, MonadPQ schemas tx)
106+ -> tx x -- ^ run inside an ephemeral transaction
108+ephemerally mode tx = do
109+ manipulate_ $ begin mode
111+ manipulate_ rollback
114+{- | Run a computation `ephemerally` in `defaultMode`. -}
116+ :: (MonadIO tx, MonadPQ schemas tx)
117+ => tx x -- ^ run inside an ephemeral transaction
119+ephemerally_ = ephemerally defaultMode
97-- | @BEGIN@ a transaction.
121-- | @BEGIN@ a transaction.
98begin :: TransactionMode -> Manipulation_ schemas () ()
122begin :: TransactionMode -> Manipulation_ schemas () ()
99begin mode = UnsafeManipulation $ "BEGIN" <+> renderSQL mode
123begin mode = UnsafeManipulation $ "BEGIN" <+> renderSQL mode