File tree Expand file tree Collapse file tree 3 files changed +6
-4
lines changed
Expand file tree Collapse file tree 3 files changed +6
-4
lines changed Original file line number Diff line number Diff line change 44import asyncpg
55
66from .base import Engine
7+ from ..query .base import Query
78
89
910class 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 ())
You can’t perform that action at this time.
0 commit comments