from __future__ import annotations from sqlalchemy import select from sqlalchemy.ext.asyncio import AsyncSession from app.models.entities import CacheEntry class CacheEntryRepository: def __init__(self, session: AsyncSession) -> None: self.session = session async def get_ready_by_blob(self, blob_id: str) -> CacheEntry | None: result = await self.session.execute( select(CacheEntry).where( CacheEntry.blob_id == blob_id, CacheEntry.status == "ready", ) ) return result.scalar_one_or_none() async def create(self, entry: CacheEntry) -> CacheEntry: self.session.add(entry) await self.session.flush() await self.session.refresh(entry) return entry async def save(self, entry: CacheEntry) -> CacheEntry: await self.session.flush() await self.session.refresh(entry) return entry