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

Savepoint support for Transaction #41

Closed
kaol opened this issue Dec 13, 2015 · 2 comments
Closed

Savepoint support for Transaction #41

kaol opened this issue Dec 13, 2015 · 2 comments

Comments

@kaol
Copy link

kaol commented Dec 13, 2015

As it stands, hasql supports performing transactions that end either in a rollback or a commit. Would you consider adding a third option, namely savepoints? That would allow for sane transaction isolation while letting interleaving IO in between. That is, perform this operation at the end of Hasql.Transaction.run: http://www.postgresql.org/docs/current/static/sql-savepoint.html

Then, when you continue the transaction starting from that savepoint, you'd perform a rollback to savepoint instead of an abort, if need be.

run would need to have a type like

run :: Transaction a -> ... -> IO (Either Query.ResultsError (Either (SavePoint a) a))

and Transaction should have operations for ending the transaction with a savepoint instead of a return, and for rolling back to a specific savepoint instead of just the latest one. Continuing the transaction would involve a version of run that would take the savepoint instead of the isolation, mode and connection parameters.

I'm not certain how all the kinks of an API with savepoints would go. I may try to sketch an implementation myself, yet. I'll need to familiarize myself with the new hasql version first. But I'd love to hear first whether this kind of functionality would be anything you'd care to see in hasql. I like the purity of leaving IO out of SQL transactions but I feel that there's a way to have my cake and eat it too.

@nikita-volkov
Copy link
Owner

It is basically a different abstraction that you're talking about. You need different properties from it and expect a bit different behaviour. Hence it simply makes a perfect case for releasing a different package, and it's great, because one of my primary intents with this giant restructuring of the ecosystem was to make it extendable.

This is why my interpretation of the transaction with the accent on the purity and STM-inspired behaviour is released only as an extension-package. It's done so intentionally, with one of the reasons being to allow alternative interpretations like yours to be released as well and compete with equal status, instead of us having endless debates about which interpretation is better.

IOW just go ahead and release a package with your view on transactions, and good luck!

@kaol
Copy link
Author

kaol commented Feb 9, 2016

An update of sorts for this. I don't even know myself now if I even wanted to mix savepoints to this, and upon further reading, I saw that they don't really offer help with serialization conflicts.

But I've got started with coding with the new API version and I like getting access to making queries without necessarily having to have them be whole transactions. For anyone curious about it, I've made some code for snap to use hasql with it, and for authenticating and getting user's data.

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

2 participants