delete protocol
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user