archive-backend/services/videos.py
2026-11-07 11:40:36 +00:00

15 lines
448 B
Python

# services/videos.py
from sqlalchemy import select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import selectinload
from models import Video
async def load_video_with_relations(db: AsyncSession, video_id: int) -> Video:
stmt = (
select(Video)
.options(selectinload(Video.channel), selectinload(Video.playlist))
.where(Video.id == video_id)
)
return (await db.execute(stmt)).scalar_one()