Migrating to v4.0¶
This page covers every breaking change introduced in v4.0 and the steps required to update your code.
Database¶
lock_tables now takes a session_maker instead of a session¶
The first argument of lock_tables changed from an AsyncSession instance to an async_sessionmaker.
The function creates and manages its own dedicated session internally, yielding it to the caller.
from fastapi_toolsets.db import lock_tables, LockMode
async with lock_tables(session=session, tables=[User, Account]):
user = await UserCrud.get(session, [User.id == 1])
user.balance += 100
# With a custom lock mode
async with lock_tables(session, [Order], mode=LockMode.EXCLUSIVE):
await process_order(session, order_id)
from fastapi_toolsets.db import lock_tables, LockMode
async with lock_tables(session_maker=session_maker, tables=[User, Account]) as session:
user = await UserCrud.get(session, [User.id == 1])
user.balance += 100
# With a custom lock mode
async with lock_tables(session_maker, [Order], mode=LockMode.EXCLUSIVE) as session:
await process_order(session, order_id)