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

With statement to can use QueryBuilder or Model operations inside transaction #231

Closed
Marlysson opened this issue Oct 31, 2020 · 2 comments
Labels
feature request A feature that does not yet exist but will be a good addition to the library hard These issues are geared for people who have contributed to the project a lot

Comments

@Marlysson
Copy link
Contributor

Marlysson commented Oct 31, 2020

Support to run:

with db.transaction("staging") as db:
    db.table('charges').update({paid: True})

or a Model operations:

with db.transaction("staging"):
    charge = Charge.find(2)
    charge.update(paid=True)

The difference to #229 is that here we can run some operation outside of a transaction and rollback just some code. In #229 we can only revert couple operations.

def charge(customer):
    charge = Charge.create({"customer":X , "paid":False})

    with db.transaction("staging"):
        payment = Payment.find(2)
        payment.update(value=100)

So, if some exception raises, just snippet inside with statement would be rollbacked. In this exemple the "history" of charges of customer would keep ( even if the payment would'nt be "done" ).

Make sense @josephmancuso ?

@Marlysson Marlysson changed the title With statement to can use QueryBuilder and Model operations inside transaction With statement to can use QueryBuilder or Model operations inside transaction Oct 31, 2020
@girardinsamuel
Copy link
Contributor

Yes could be great to use this instead of the decorator approach for some use cases.

If you think it makes sense, I can add the context manager feature to the decorator class to be able to use both

@josephmancuso josephmancuso added the enhancement A feature that exists, works as intended but needs to be improved label Oct 31, 2020
@josephmancuso josephmancuso added feature request A feature that does not yet exist but will be a good addition to the library and removed enhancement A feature that exists, works as intended but needs to be improved labels Dec 19, 2020
@josephmancuso josephmancuso added the hard These issues are geared for people who have contributed to the project a lot label Jan 9, 2021
@josephmancuso
Copy link
Member

#375

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request A feature that does not yet exist but will be a good addition to the library hard These issues are geared for people who have contributed to the project a lot
Projects
None yet
Development

No branches or pull requests

3 participants