on dev help sign in
remove transactionallySchema
commitb333355b656f68c2fa0f7e332ebf96bfd8ddc3ee authorEitan Chatav <eitan@Eitans-MacBook-Pro.local> dateSat 13 Apr 2019, 19:44 (8 years ago) parentdb3aeaf
2 files changed+16−39
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+2−2 squeal-postgresql/src/Squeal/PostgreSQL/Transaction.hs+14−37
squeal-postgresql/src/Squeal/PostgreSQL/Migration.hs+2−2
@@ -251,7 +251,7 @@ instance Migratory (Terminally PQ IO) where
251251 migrateUp migration = unsafePQ $
252252 define createMigrations
253253 & pqBind okResult
254− & pqThen (transactionallySchema_ (upMigrations migration))
254+ & pqThen (transactionally_ (upMigrations migration))
255255
256256 where
257257
@@ -284,7 +284,7 @@ instance Migratory (Terminally PQ IO) where
284284 migrateDown migrations = unsafePQ $
285285 define createMigrations
286286 & pqBind okResult
287− & pqThen (transactionallySchema_ (downMigrations migrations))
287+ & pqThen (transactionally_ (downMigrations migrations))
288288
289289 where
290290
squeal-postgresql/src/Squeal/PostgreSQL/Transaction.hs+14−37
@@ -24,8 +24,6 @@ module Squeal.PostgreSQL.Transaction
2424 , begin
2525 , commit
2626 , rollback
27− , transactionallySchema
28− , transactionallySchema_
2927 -- * Transaction Mode
3028 , TransactionMode (..)
3129 , defaultMode
@@ -36,18 +34,17 @@ module Squeal.PostgreSQL.Transaction
3634 ) where
3735
3836import Control.Monad
39−import Generics.SOP
4037import UnliftIO
4138
42−import qualified Database.PostgreSQL.LibPQ as LibPQ
43−
4439import Squeal.PostgreSQL.Manipulation
4540import Squeal.PostgreSQL.Render
4641import Squeal.PostgreSQL.PQ
4742
48−{- | Run a computation `transactionally`; first `begin`,
49−then run the computation, then if it raises an exception
50−`rollback`, otherwise `commit` and `return` the result.
43+{- | Run a computation `transactionally`;
44+first `begin`,
45+then run the computation,
46+`onException` `rollback` and rethrow the exception,
47+otherwise `commit` and `return` the result.
5148-}
5249transactionally
5350 :: (MonadUnliftIO tx, MonadPQ schemas tx)
@@ -60,7 +57,7 @@ transactionally mode tx = mask $ \restore -> do
6057 commit
6158 return result
6259
63−-- | Run a computation `transactionally_` in `defaultMode`.
60+-- | Run a computation `transactionally_`, in `defaultMode`.
6461transactionally_
6562 :: (MonadUnliftIO tx, MonadPQ schemas tx)
6663 => tx x -- ^ run inside a transaction
@@ -69,11 +66,12 @@ transactionally_ = transactionally defaultMode
6966
7067{- |
7168`transactionallyRetry` a computation;
72−first `begin`,
73−then `try` the computation,
74−if it raises an serialization failure then `rollback` and restart the transaction,
75−if it raises any other exception then `rollback` and rethrow the exception,
76−otherwise `commit` and `return` the result.
69+
70+* first `begin`,
71+* then `try` the computation,
72+ - if it raises a serialization failure then `rollback` and restart the transaction,
73+ - if it raises any other exception then `rollback` and rethrow the exception,
74+ - otherwise `commit` and `return` the result.
7775-}
7876transactionallyRetry
7977 :: (MonadUnliftIO tx, MonadPQ schemas tx)
@@ -98,35 +96,14 @@ begin :: MonadPQ schemas tx => TransactionMode -> tx ()
9896begin mode = void . manipulate . UnsafeManipulation $
9997 "BEGIN" <+> renderSQL mode <> ";"
10098
101−-- | @COMMIT@ a schema invariant transaction.
99+-- | @COMMIT@ a transaction.
102100commit :: MonadPQ schemas tx => tx ()
103101commit = void . manipulate $ UnsafeManipulation "COMMIT;"
104102
105−-- | @ROLLBACK@ a schema invariant transaction.
103+-- | @ROLLBACK@ a transaction.
106104rollback :: MonadPQ schemas tx => tx ()
107105rollback = void . manipulate $ UnsafeManipulation "ROLLBACK;"
108106
109−-- | Run a schema changing computation `transactionallySchema`.
110−transactionallySchema
111− :: MonadUnliftIO io
112− => TransactionMode
113− -> PQ schemas0 schemas1 io x
114− -> PQ schemas0 schemas1 io x
115−transactionallySchema mode u = PQ $ \ conn -> mask $ \ restore -> do
116− _ <- liftIO . LibPQ.exec (unK conn) $
117− "BEGIN" <+> renderSQL mode <> ";"
118− x <- restore (unPQ u conn)
119− `onException` (liftIO (LibPQ.exec (unK conn) "ROLLBACK"))
120− _ <- liftIO $ LibPQ.exec (unK conn) "COMMIT"
121− return x
122−
123−-- | Run a schema changing computation `transactionallySchema_` in `defaultMode`.
124−transactionallySchema_
125− :: MonadUnliftIO io
126− => PQ schemas0 schemas1 io x
127− -> PQ schemas0 schemas1 io x
128−transactionallySchema_ = transactionallySchema defaultMode
129−
130107-- | The available transaction characteristics are the transaction `IsolationLevel`,
131108-- the transaction `AccessMode` (`ReadWrite` or `ReadOnly`), and the `DeferrableMode`.
132109data TransactionMode = TransactionMode