event listens for sqlalchemy

This commit is contained in:
IluaAir
2025-08-06 23:38:17 +03:00
parent acb3eefcbe
commit 93cf7b2d24
5 changed files with 33 additions and 14 deletions

View File

@@ -1,6 +1,5 @@
from sqlalchemy import delete, select, update
from schemas.users import User
from src.models import UsersORM
from src.repository.base import BaseRepo
@@ -18,7 +17,12 @@ class UsersRepo(BaseRepo):
await self.session.execute(delete(self.model).where(self.model.id == id))
async def update_one(self, id: int, data: dict) -> UsersORM:
stmt = update(self.model).where(self.model.id == id).values(data.model_dump(exclude_unset=True)).returning(self.model)
stmt = (
update(self.model)
.where(self.model.id == id)
.values(data.model_dump(exclude_unset=True))
.returning(self.model)
)
result = await self.session.execute(stmt)
model = result.scalar_one()
return model