26 lines
994 B
Python
26 lines
994 B
Python
from typing import List, Dict, Any
|
|
from app.core.database.connection import SQLiteExecutor
|
|
from app.core.dto.training import TrainingDTO
|
|
|
|
|
|
class TrainingOps:
|
|
TABLE_NAME: str = "trainings"
|
|
|
|
def __init__(self, executor: SQLiteExecutor) -> None:
|
|
self._executor = executor
|
|
|
|
async def create(self, training: TrainingDTO) -> int:
|
|
query = f"INSERT INTO {self.TABLE_NAME} (date, trainer) VALUES (?, ?)"
|
|
return await self._executor.execute_mod_query(
|
|
query, (training.date, training.trainer)
|
|
)
|
|
|
|
async def list(self) -> List[Dict[str, Any]]:
|
|
query = f"SELECT * FROM {self.TABLE_NAME}"
|
|
return await self._executor.execute_query(query)
|
|
|
|
async def delete(self, list_of_ids: List[int]) -> None:
|
|
placeholders: str = ",".join("?" * len(list_of_ids))
|
|
query = f"DELETE FROM {self.TABLE_NAME} WHERE id IN ({placeholders})"
|
|
await self._executor.execute_mod_query(query, tuple(list_of_ids))
|
|
return None
|