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.scalars().all() @staticmethod async def get_by_id(id_: int) -> Optional[ChExperimentDBExperimentData]: async with async_session() as session: result = session.get(ChExperimentDBExperimentData, id_) return result @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()