You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

31 lines
942 B

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