Created
May 16, 2012 15:23
-
-
Save jacobian/2711219 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@transaction.commit_manually | |
def foo(): | |
db.execute("SELECT ...") | |
bar() | |
db.execute("SELECT ...") | |
transaction.commit() | |
def bar(): | |
db.execute("INSERT ...") | |
### the above is exactly the same as .... | |
@transaction.commit_manually | |
def foo(): | |
db.execute("SELECT ...") | |
db.execute("INSERT ...") # <--- as if bar was inlined | |
db.execute("SELECT ...") | |
transaction.commit() | |
### and remember that decorators aren't "magic", they just run code before a function | |
### so the above is also the same as ... | |
# <---- no decorator | |
def foo(): | |
transaction.managed(True) # <---- it's a little more complex, but that's basically all commit_manually does! | |
db.execute("SELECT ...") | |
db.execute("INSERT ...") # <--- Or a call to bar() here, same thing | |
db.execute("SELECT ...") | |
transaction.commit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment