from common.db.base import execute, fetchone, fetchall async def insert_file( analysis_run_id: str, file_type: str, file_name: str, file_url: str, size_bytes: int | None = None, hospital_id: str | None = None, ) -> int: return await execute( "INSERT INTO file_data (analysis_run_id, hospital_id, file_type, file_name, file_url, size_bytes)" " VALUES (%s, %s, %s, %s, %s, %s)", (analysis_run_id, hospital_id, file_type, file_name, file_url, size_bytes), ) async def select_run_files(analysis_run_id: str) -> list[dict]: return await fetchall( "SELECT id, file_type, file_name, file_url, size_bytes, created_at" " FROM file_data WHERE analysis_run_id = %s AND is_deleted = FALSE" " ORDER BY created_at DESC", (analysis_run_id,), ) async def select_file(file_id: int, analysis_run_id: str) -> dict | None: return await fetchone( "SELECT id FROM file_data WHERE id = %s AND analysis_run_id = %s", (file_id, analysis_run_id), ) async def delete_file(file_id: int) -> None: await execute( "UPDATE file_data SET is_deleted = TRUE WHERE id = %s AND is_deleted = FALSE", (file_id,), )