How to use transaction (examples)? #402
Answered
by
aminalaee
ETretyakov
asked this question in
Q&A
-
Could someone provide examples on how to use transactions? There are incomplete examples in documentation but could you provide more exact examples? async with database.transaction():
[what is here?] transaction = await database.transaction()
try:
await transaction.start()
[what is here?]
except:
await transaction.rollback()
else:
await transaction.commit() |
Beta Was this translation helpful? Give feedback.
Answered by
aminalaee
Oct 3, 2021
Replies: 1 comment 1 reply
-
Hi, transaction = await database.transaction()
try:
[INSERT/UPDATE] inside that transaction....
except:
await transaction.rollback()
else:
await transaction.commit() You can do INSERT or UPDATE within that transaction, and commit/rollback based on that. |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
aminalaee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
First off, the example you see in the docs is invalid. That will be fixed when 0.5.3 is merged. You don't need to call
await tranasaction.start()
.You can do INSERT or UPDATE within that transaction, and commit/rollback based on that.