From cc2e45619a3758e67ba3fa8ed97175f905b9e1db Mon Sep 17 00:00:00 2001 From: Inohara Date: Thu, 17 Oct 2024 16:33:41 +0400 Subject: [PATCH] =?UTF-8?q?=D1=80=D0=B5=D0=BF=D0=BE=D0=B7=D0=B8=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B9=20=D0=B4=D0=BB=D1=8F=20ch=5Fexperiment?= =?UTF-8?q?db=5Fexperiment=5Fdata?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ch_experimentdb_experiment_data_repos.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 db/repositories/ch_experimentdb_experiment_data_repos.py diff --git a/db/repositories/ch_experimentdb_experiment_data_repos.py b/db/repositories/ch_experimentdb_experiment_data_repos.py new file mode 100644 index 0000000..39cf088 --- /dev/null +++ b/db/repositories/ch_experimentdb_experiment_data_repos.py @@ -0,0 +1,44 @@ +from typing import Optional +from sqlalchemy import select +from db.db_connection import async_session +from db.models.ch_experimentdb_experiment_data_model import ChExperimentDBExperimentData + + +class ChExperimentDBExperimentDataRepository: + @staticmethod + async def get_all() -> Optional[list[ChExperimentDBExperimentData]]: + async with async_session() as session: + result = await session.execute(select(ChExperimentDBExperimentData)) + return result.scalar.all() + + @staticmethod + async def get_by_id(id_: int) -> Optional[ChExperimentDBExperimentData]: + async with async_session() as session: + result = await session.execute(select(ChExperimentDBExperimentData).where(ChExperimentDBExperimentData.id == id_)) + return result.scalars().first() + + + @staticmethod + async def create(volume: float, + nitrogen_oxide_emission: float, + temperature: float, + co_fraction: float, + co2_fraction: float, + x: float, + y: float, + z: float, + file_id: str): + new_data = ChExperimentDBExperimentData( + volume=volume, + nitrogen_oxide_emission=nitrogen_oxide_emission, + temperature=temperature, + co_fraction=co_fraction, + co2_fraction=co2_fraction, + x=x, + y=y, + z=z, + file_id=file_id + ) + async with async_session() as session: + session.add(new_data) + await session.commit()