mirror of
https://github.com/d3vyce/fastapi-toolsets.git
synced 2026-08-04 23:54:09 +00:00
1.3 KiB
1.3 KiB
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.
=== "Before (v3)"
```python
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=session, tables=[Order], mode=LockMode.EXCLUSIVE):
await process_order(session, order_id)
```
=== "Now (v4)"
```python
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=session_maker, tables=[Order], mode=LockMode.EXCLUSIVE
) as session:
await process_order(session, order_id)
```