Skip to content

Commit 0a65b4b

Browse files
committed
transaction accepts query objects
1 parent d7d983d commit 0a65b4b

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

aragorm/engine/postgres.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,30 @@
44
import asyncpg
55

66
from .base import Engine
7+
from ..query.base import Query
78

89

910
class Transaction():
1011
"""
1112
Usage:
1213
13-
with await Transaction() as transaction:
14-
transaction.add(Foo.create())
14+
transaction = engine.Transaction()
15+
transaction.add(Foo.create())
16+
transaction.run_sync()
1517
"""
1618

1719
def __init__(self, engine):
1820
self.engine = engine
1921
self.queries = []
2022

21-
def add(self, *query: str):
23+
def add(self, *query: Query):
2224
self.queries += list(query)
2325

2426
async def run(self):
2527
connection = await asyncpg.connect(**self.engine.config)
2628
async with connection.transaction():
2729
for query in self.queries:
28-
await connection.execute(query)
30+
await connection.execute(query.__str__())
2931

3032
def run_sync(self):
3133
return asyncio.run(self.run())

tests/engine/__init__.py

Whitespace-only changes.

tests/engine/test_transaction.py

Whitespace-only changes.

0 commit comments

Comments
 (0)