feat: pagination hints

This commit is contained in:
2026-08-19 21:33:22 +07:00
parent 981db23b6f
commit 04be991865
5 changed files with 57 additions and 1 deletions

View File

@@ -83,6 +83,40 @@ class ProductRepository:
await session.commit()
return product
async def count_products_by_category(
self,
session: AsyncSession,
category_id: int,
*,
include_hidden: bool = False,
) -> int:
stmt = select(func.count()).select_from(Product).where(
Product.category_id == category_id
)
if not include_hidden:
stmt = stmt.where(Product.is_hidden.is_(False))
return await session.scalar(stmt)
async def count_search(
self,
session: AsyncSession,
query: str,
*,
include_hidden: bool = False,
) -> int:
ts_query = func.plainto_tsquery("simple", query)
stmt = select(func.count()).select_from(Product).where(
Product.search_vector.op("@@")(ts_query)
)
if not include_hidden:
stmt = stmt.where(Product.is_hidden.is_(False))
return await session.scalar(stmt)
async def search(
self,
session: AsyncSession,