From 9283c23b2fc525c33d529a9d5c744508ed6b39e0 Mon Sep 17 00:00:00 2001 From: Vicki Boykis Date: Wed, 15 Jan 2025 07:40:22 -0500 Subject: [PATCH] orm get jobs by experiment --- .../python/mzai/backend/backend/repositories/jobs.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lumigator/python/mzai/backend/backend/repositories/jobs.py b/lumigator/python/mzai/backend/backend/repositories/jobs.py index 238438a67..e7aba64f4 100644 --- a/lumigator/python/mzai/backend/backend/repositories/jobs.py +++ b/lumigator/python/mzai/backend/backend/repositories/jobs.py @@ -1,5 +1,6 @@ from uuid import UUID +from sqlalchemy import desc from sqlalchemy.orm import Session from backend.records.jobs import JobRecord, JobResultRecord @@ -16,8 +17,7 @@ def __init__(self, session: Session): super().__init__(JobResultRecord, session) def get_by_job_id(self, job_id: UUID) -> JobResultRecord | None: - return ( - self.session.query(JobResultRecord) - .where(JobResultRecord.job_id == job_id) - .first() - ) + return self.session.query(JobResultRecord).where(JobResultRecord.job_id == job_id).first() + + def get_jobs_by_experiment_id(self, experiment_id: UUID) -> list[JobRecord]: + return self.session.query(JobRecord).order_by(desc(JobRecord.created_at)).limit(2).all()