delete protocol

This commit is contained in:
IluaAir
2025-09-28 22:34:14 +03:00
parent 64dcc77518
commit 91daaf9275
7 changed files with 8 additions and 17 deletions

View File

@@ -2,5 +2,5 @@ from src.models.tokens import RefreshTokensORM
from src.repository.base import BaseRepo
class AuthRepo(BaseRepo):
class AuthRepo(BaseRepo[RefreshTokensORM]):
model: type[RefreshTokensORM] = RefreshTokensORM

View File

@@ -3,9 +3,7 @@ from typing import Any, Generic, Mapping, Sequence, Type, TypeVar
from sqlalchemy import delete, insert, select, update
from sqlalchemy.ext.asyncio import AsyncSession
from src.core.interfaces import HasId
ModelType = TypeVar("ModelType", bound=HasId)
ModelType = TypeVar("ModelType")
class BaseRepo(Generic[ModelType]):
@@ -45,12 +43,9 @@ class BaseRepo(Generic[ModelType]):
async def delete_one(self, **filter_by) -> None:
await self.session.execute(delete(self.model).filter_by(**filter_by))
async def update_one(self, id: int, data: dict[str, Any]) -> ModelType:
async def update_one(self, data: dict[str, Any], **filter_by: Any) -> ModelType:
stmt = (
update(self.model)
.where(self.model.id == id)
.values(data)
.returning(self.model)
update(self.model).filter_by(**filter_by).values(data).returning(self.model)
)
result = await self.session.execute(stmt)
model = result.scalar_one()

View File

@@ -2,5 +2,5 @@ from src.models.tasks import TasksORM
from src.repository.base import BaseRepo
class TasksRepo(BaseRepo):
class TasksRepo(BaseRepo[TasksORM]):
model: type[TasksORM] = TasksORM

View File

@@ -9,7 +9,7 @@ from src.models.tasks import TasksORM
from src.repository.base import BaseRepo
class UsersRepo(BaseRepo):
class UsersRepo(BaseRepo[UsersORM]):
model: type[UsersORM] = UsersORM
async def get_one_with_load(