aiopg/psycopg2自动提交和交易
问题描述:
我的疑问是非常SQLish但aiopg/psycopg2自动提交和交易
由于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;')
我怀疑是因为它完全地同步的,如果有一个回退将已在同一时间跨度被处理其他的命令也rolledback或将你回滚的基于连接的?
谢谢!
答
回滚是基于连接的。
感谢piro,我结束了使用asyncpg,因为内置事务我觉得比手动创建它们更安全。 – monobot