2024-10-27 23:29:52 +04:00
|
|
|
|
from typing import Sequence
|
2024-10-28 13:30:02 +04:00
|
|
|
|
from typing_extensions import deprecated
|
2024-10-27 23:29:52 +04:00
|
|
|
|
|
2024-10-14 21:18:07 +04:00
|
|
|
|
from sqlalchemy import select
|
2024-10-27 23:29:52 +04:00
|
|
|
|
from sqlalchemy import update, delete
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
|
2024-10-14 21:18:07 +04:00
|
|
|
|
from db.models.recycling_parameters_model import RecyclingParameters
|
|
|
|
|
|
2024-10-28 13:30:02 +04:00
|
|
|
|
@deprecated(
|
|
|
|
|
"теперь есть параметризованный круд, а уже свои специфичные методы у каждой сущности в своем репозитории"
|
|
|
|
|
)
|
2024-10-14 21:18:07 +04:00
|
|
|
|
class RecyclingParametersRepository:
|
2024-10-27 23:29:52 +04:00
|
|
|
|
def __init__(self, session: AsyncSession):
|
|
|
|
|
self.session = session
|
|
|
|
|
|
|
|
|
|
async def get_all(self) -> Sequence[RecyclingParameters]:
|
|
|
|
|
result = await self.session.execute(select(RecyclingParameters))
|
|
|
|
|
return result.scalars().all()
|
|
|
|
|
|
|
|
|
|
async def get_by_id(self, id: int) -> RecyclingParameters:
|
|
|
|
|
result = await self.session.execute(select(RecyclingParameters).where(RecyclingParameters.id == id))
|
|
|
|
|
return result.scalar_one_or_none()
|
|
|
|
|
|
|
|
|
|
async def create(self, new_data: RecyclingParameters):
|
|
|
|
|
self.session.add(new_data)
|
|
|
|
|
await self.session.commit()
|
|
|
|
|
|
|
|
|
|
async def update(self, id: int, updated_data: dict):
|
|
|
|
|
stmt = (
|
|
|
|
|
update(RecyclingParameters).
|
|
|
|
|
where(RecyclingParameters.id == id).
|
|
|
|
|
values(**updated_data)
|
2024-10-22 16:46:39 +04:00
|
|
|
|
)
|
2024-10-27 23:29:52 +04:00
|
|
|
|
await self.session.execute(stmt)
|
|
|
|
|
await self.session.commit()
|
|
|
|
|
|
|
|
|
|
async def delete(self, id: int):
|
|
|
|
|
stmt = delete(RecyclingParameters).where(RecyclingParameters.id == id)
|
|
|
|
|
await self.session.execute(stmt)
|
|
|
|
|
await self.session.commit()
|