Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

question about transaction management? #15

Closed
andersbohn opened this issue Aug 24, 2020 · 3 comments
Closed

question about transaction management? #15

andersbohn opened this issue Aug 24, 2020 · 3 comments

Comments

@andersbohn
Copy link

Thanks for the tranzactio code, I experimented a bit on a fork against a local postgres, but wasn't sure if creating a PR for a question was pertinent?
I have a running REST-ZIO-Doobie-HikariTransactor-project, and I would like to make it more clear in terms of transaction management.
But with tranzactio, if I add a unique constraint and duplicate insert of alexander in an AppLayer, should each TranzactIO[_]/tzio be a transaction, or the whole thing.
_ <- PersonQueries.insert(Person("Alexander", "Harris")).orElse(Task.succeed(()))
Looks like everything is rolled back including the DDL, but then I don't know how have that happen per REST-service-request.
Nor how to have something like orElse catch an error and actually compensating with a DML (eg inserting on an error message log or status)
Anyway, any help is appreciated :)

@PawelJ-PL
Copy link

I am not the author of this library, but I will try to answer your question.
There can be more than one query in a transaction (in TranzacIO effect). The transaction is commited or rolled back for the whole block of transactionOrDie (or similar), which may also contain operations unrelated to the database (such as logging).
Finally, you can perform any operations (such as orElse or catchAll) on the output effect.
I'm not sure that this answers your question.

@gaelrenoux
Copy link
Owner

Typically, in a REST project, a REST request would correspond to a single transaction. So, you would construct your ZIO as usual, including tzio's as needed within other operations, and in the end you would have a ZIO that has a Connection in the dependencies. Then, in the REST layer, you would run the transaction (e.g. using transactionOrDie), then handle both success and failure by generating appropriate REST responses for each case.

I'm not sure why you would have DDL actions when handling a REST request? Anyway, transaction-handling for DDL actions is DBMS-dependent. On some DBMS, they are considered part of the transaction and will be rollbacked if needed, on other they will be applied immediately and can't be rollbacked, and it can even differ for different actions (e.g. dropping a table vs creating one). Nothing I can do about it.

Does that answer your question?

@andersbohn
Copy link
Author

@gaelrenoux yes, thanks 👍
Exactly what I missed in the LayeredApp is that complete transactionOrWiden around all the ZIOs made with tzios. Which are doobie trasn calls on the transactor, which I suppose is what I should have understood by reading doobie doc more carefully.
(DDL was only circumstantial, depends on DB, got it.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants