我的怀疑是非常 SQLish 但
由于 psycopg2 异步连接是自动提交的,我手动设置定义的事务,然后在同一个游标/连接中关闭。
像这样:
async def transaction(self, queries):
async with aiopg.create_pool(connection) as pool:
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute('BEGIN transaction;')
for query in queries:
await cur.execute(query)
await cur.execute('COMMIT transaction;')
我的疑问是,由于它完全异步,如果有回滚,在同一时间跨度内处理的其他命令也会回滚还是基于连接回滚?
谢谢!!