from sqlalchemy.ext.asyncio import AsyncSession from sqlalchemy import select from typing import Optional from db.models import Category class CategoriesRepository: async def get_category_by_id( self, session: AsyncSession, category_id: int ) -> Optional[Category]: stmt = select(Category).where(Category.id == category_id) return await session.scalar(stmt) async def get_category_by_parent_id( self, session: AsyncSession, parent_id: Optional[int] = None ) -> list[Category]: stmt = select(Category).where(Category.parent_id == parent_id) result = await session.scalars(stmt) return list(result)