f1tness_parser/app/core/database/models/approach.py

26 lines
1 KiB
Python

from typing import List, Dict, Any
from app.core.database.connection import SQLiteExecutor
from app.core.dto.training import ApproachDTO
class ApproachOps:
TABLE_NAME: str = "approaches"
def __init__(self, executor: SQLiteExecutor) -> None:
self._executor = executor
async def create(self, approach: ApproachDTO) -> int:
query = f"INSERT INTO {self.TABLE_NAME} (exercise_id, weight, reps) VALUES (?, ?, ?)"
return await self._executor.execute_mod_query(
query, (approach.exercise_id, approach.weight, approach.reps)
)
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