on dev help sign in
ephemeral

rollback on exceptions as well, duh

commit2645387887ec0fb1bac6edd253ab49f938491996 authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateTue 30 Apr 2019, 20:47 (7 years ago) parentcd3de98
1 file changed+5−6
squeal-postgresql/src/Squeal/PostgreSQL/Transaction.hs+5−6
squeal-postgresql/src/Squeal/PostgreSQL/Transaction.hs+5−6
@@ -97,23 +97,22 @@ transactionallyRetry mode tx = mask $ \restore ->
9797 Right x -> return x
9898
9999{- | Run a computation `ephemerally`;
100−First `begin`, then run the computation, `rollback` and `return`
101−its result.
100+Like `transactionally` but always `rollback`, useful in testing.
102101-}
103102ephemerally
104− :: (MonadIO tx, MonadPQ schemas tx)
103+ :: (MonadUnliftIO tx, MonadPQ schemas tx)
105104 => TransactionMode
106105 -> tx x -- ^ run inside an ephemeral transaction
107106 -> tx x
108−ephemerally mode tx = do
107+ephemerally mode tx = mask $ \restore -> do
109108 manipulate_ $ begin mode
110− result <- tx
109+ result <- restore tx `onException` (manipulate_ rollback)
111110 manipulate_ rollback
112111 return result
113112
114113{- | Run a computation `ephemerally` in `defaultMode`. -}
115114ephemerally_
116− :: (MonadIO tx, MonadPQ schemas tx)
115+ :: (MonadUnliftIO tx, MonadPQ schemas tx)
117116 => tx x -- ^ run inside an ephemeral transaction
118117 -> tx x
119118ephemerally_ = ephemerally defaultMode