feat: pagination hints
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user