-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,6 +70,37 @@ async def main(): | |
asyncio.run(main()) | ||
``` | ||
|
||
### Transaction Support | ||
|
||
Litequery also supports transactions, allowing you to execute multiple queries | ||
atomicaly. | ||
|
||
```python | ||
import litequery | ||
import asyncio | ||
|
||
async def main(): | ||
lq = litequery.setup("database.db", "queries.sql") | ||
await lq.connect() | ||
|
||
try: | ||
async with lq.transaction(): | ||
await lq.insert_user(name="Charlie", email="[email protected]") | ||
raise Exception("Force rollback") | ||
await lq.insert_user(name="Eve", email="[email protected]") | ||
except Exception: | ||
print("Transaction failed") | ||
|
||
users = await lq.get_all_users() | ||
print(users) | ||
|
||
await lq.disconnect() | ||
|
||
|
||
asyncio.run(main()) | ||
|
||
``` | ||
|
||
## Wrapping Up | ||
|
||
Litequery is all about simplicity and efficiency. Why wrestle with bloated ORMs | ||
|