2024-10-27 23:29:52 +04:00
|
|
|
from typing import Optional, Sequence
|
|
|
|
|
|
|
|
from sqlalchemy import delete as delete_
|
|
|
|
from sqlalchemy import update as update_
|
2024-10-18 16:42:39 +04:00
|
|
|
from sqlalchemy.future import select
|
2024-10-27 23:29:52 +04:00
|
|
|
|
2024-10-14 21:18:07 +04:00
|
|
|
from db.models.load_parameters_model import LoadParameters
|
2024-10-27 23:29:52 +04:00
|
|
|
from db.postgres_db_connection import async_session_postgres
|
|
|
|
|
|
|
|
|
2024-10-28 13:30:02 +04:00
|
|
|
# async def get_all() -> Sequence[LoadParameters]:
|
|
|
|
# async with async_session_postgres() as session:
|
|
|
|
# result = await session.execute(select(LoadParameters))
|
|
|
|
# return result.scalars().all()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# async def get_by_id(id: int) -> LoadParameters:
|
|
|
|
# async with async_session_postgres() as session:
|
|
|
|
# result = await session.execute(select(LoadParameters).where(LoadParameters.id == id))
|
|
|
|
# return result.scalar_one_or_none()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# async def create(new_data: LoadParameters):
|
|
|
|
# async with async_session_postgres() as session:
|
|
|
|
# session.add(new_data)
|
|
|
|
# await session.commit()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# async def update(id: int, updated_data: dict):
|
|
|
|
# async with async_session_postgres() as session:
|
|
|
|
# stmt = (
|
|
|
|
# update_(LoadParameters).
|
|
|
|
# where(LoadParameters.id == id).
|
|
|
|
# values(**updated_data)
|
|
|
|
# )
|
|
|
|
# await session.execute(stmt)
|
|
|
|
# await session.commit()
|
|
|
|
#
|
|
|
|
#
|
|
|
|
# async def delete(id: int) -> bool:
|
|
|
|
# async with async_session_postgres() as session:
|
|
|
|
# stmt = delete_(LoadParameters).where(LoadParameters.id == id)
|
|
|
|
# result = await session.execute(stmt)
|
|
|
|
# await session.commit()
|
|
|
|
# return result.rowcount > 0
|
2024-10-18 16:42:39 +04:00
|
|
|
|
|
|
|
|
2024-10-27 23:29:52 +04:00
|
|
|
# class LoadParametersRepository:
|
|
|
|
# def __init__(self, session: AsyncSession):
|
|
|
|
# self.session = session
|
|
|
|
#
|
|
|
|
# async def get_all(self) -> Sequence[LoadParameters]:
|
|
|
|
# result = await self.session.execute(select(LoadParameters))
|
|
|
|
# return result.scalars().all()
|
|
|
|
#
|
|
|
|
# async def get_by_id(self, id: int) -> LoadParameters:
|
|
|
|
# result = await self.session.execute(select(LoadParameters).where(LoadParameters.id == id))
|
|
|
|
# return result.scalar_one_or_none()
|
|
|
|
#
|
|
|
|
# async def create(self, new_data: LoadParameters):
|
|
|
|
# self.session.add(new_data)
|
|
|
|
# await self.session.commit()
|
|
|
|
#
|
|
|
|
# async def update(self, id: int, updated_data: dict):
|
|
|
|
# stmt = (
|
|
|
|
# update_(LoadParameters).
|
|
|
|
# where(LoadParameters.id == id).
|
|
|
|
# values(**updated_data)
|
|
|
|
# )
|
|
|
|
# await self.session.execute(stmt)
|
|
|
|
# await self.session.commit()
|
|
|
|
#
|
|
|
|
# async def delete(self, id: int):
|
|
|
|
# stmt = delete_(LoadParameters).where(LoadParameters.id == id)
|
|
|
|
# await self.session.execute(stmt)
|
|
|
|
# await self.session.commit()
|