My question is the exact copy of this [question]1, but I'm asking it for syntax version > 1.4
I'm using the next syntax in my queries:
get_user_st = users.select().where(users.c.login == user.phone_number)
connection.execute(statement=get_user_st).fetchone()
Getting db:
from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.exc import SQLAlchemyError
engine_async = create_async_engine(url=config.SQLALCHEMY_ASYNCPG_URL, echo=False, future=True) # Future -use style 2.0
session_async = sessionmaker(bind=engine_async, autoflush=True, class_=AsyncSession)
async def get_db():
session = session_async()
try:
yield session
await session.commit()
except SQLAlchemyError as ex:
await session.rollback()
raise ex
finally:
await session.close()
Type of my session is:
type(postgres_session)
<class 'sqlalchemy.orm.session.AsyncSession'>
P.S. It's preferable to get not the current primary key but an upcoming/next