如何获取最后插入的id?请注意sqlalchemy
版本,因此这个问题不适用于我。
我尝试过:
async def foo(db_session: AsyncSession, login):
r1 = await db_session.execute(statement=models_users.insert().values(login=login))
r2 = await db_session.flush()
# r3 = await db_session.fetchval(...) # Error, no such method for async
r4 = await db_session.commit()
print(r2, r4, r1.fechone()) # None, None, None
print(r1.lastrowid) # 'AsyncAdapt_asyncpg_cursor' object has no attribute 'lastrowid'
SQLAlchemy 1.4.4
asyncpg 0.22.0