Module
Yoga.Postgres.Transaction
- Package
- purescript-yoga-postgres
- Repository
- rowtype-yoga/purescript-yoga-postgres
#withTransaction Source
withTransaction :: forall a. (Client -> Aff a) -> Client -> Aff a
Runs an asynchronous action in a database transaction. The transaction will be rolled back if the computation fails and committed otherwise.
Here the first insert will be rolled back:
moneyTransfer :: forall e. (Client -> Aff e Unit) -> Client -> Aff e Unit
moneyTransfer = withTransaction $ \c -> do
execute_ (Query "insert into accounts ...") c
throwError $ error "Something went wrong"
execute_ (Query "insert into accounts ...") c