66from pydantic import Field
77
88from bubble_data_api_client .client .raw_client import RawClient
9- from bubble_data_api_client .constraints import ConstraintTypes , constraint
9+ from bubble_data_api_client .constraints import Constraint , ConstraintTypes , constraint
1010
1111
1212def _get_client () -> RawClient :
@@ -48,7 +48,7 @@ async def get_many(cls, uids: list[str]) -> dict[str, typing.Self]:
4848 """Retrieve multiple things by their unique IDs, keyed by uid."""
4949 if not uids :
5050 return {}
51- items : list [typing .Self ] = await cls .list (
51+ items : list [typing .Self ] = await cls .find (
5252 constraints = [constraint ("_id" , ConstraintTypes .IN , uids )],
5353 )
5454 return {item .uid : item for item in items }
@@ -65,10 +65,10 @@ async def delete(self) -> None:
6565 response .raise_for_status ()
6666
6767 @classmethod
68- async def list (
68+ async def find (
6969 cls ,
7070 * ,
71- constraints : list | None = None ,
71+ constraints : list [ Constraint ] | None = None ,
7272 cursor : int | None = None ,
7373 limit : int | None = None ,
7474 sort_field : str | None = None ,
@@ -77,7 +77,7 @@ async def list(
7777 additional_sort_fields : list | None = None ,
7878 ) -> list [typing .Self ]:
7979 async with _get_client () as client :
80- response = await client .list (
80+ response = await client .find (
8181 cls ._typename ,
8282 constraints = constraints ,
8383 cursor = cursor ,
@@ -89,3 +89,9 @@ async def list(
8989 )
9090 response .raise_for_status ()
9191 return [cls (** item ) for item in response .json ()["response" ]["results" ]]
92+
93+ @classmethod
94+ async def count (cls , * , constraints : list [Constraint ] | None = None ) -> int :
95+ """Return total count of objects matching constraints."""
96+ async with _get_client () as client :
97+ return await client .count (cls ._typename , constraints = constraints )
0 commit comments