diff --git a/README.md b/README.md index 75e923a..b666772 100644 --- a/README.md +++ b/README.md @@ -95,6 +95,12 @@ table_rows = client.table_row_list(project, table_name, params={'offset': 100}) table_rows = client.table_row_list(project, table_name, InFilter("name", "sam")) table_rows = client.table_row_list(project, table_name, filter_obj=EqFilter("Id", 100)) +# Filter and count rows +count = client.table_count(project, table_name, filter_obj=EqFilter("Id", 100)) + +# Find one row +table_row = client.table_find_one(project, table_name, filter_obj=EqFilter("Id", 100), params={"sort": "-created_at"}) + # Retrieve a single row row_id = 10 row = client.table_row_detail(project, table_name, row_id) diff --git a/nocodb/api.py b/nocodb/api.py index aed549a..e8b0f17 100644 --- a/nocodb/api.py +++ b/nocodb/api.py @@ -26,6 +26,22 @@ def get_table_uri(self, project: NocoDBProject, table: str) -> str: ) ) + def get_table_count_uri(self, project: NocoDBProject, table: str) -> str: + return "/".join( + ( + self.get_table_uri(project, table), + 'count' + ) + ) + + def get_table_find_one_uri(self, project: NocoDBProject, table: str) -> str: + return "/".join( + ( + self.get_table_uri(project, table), + 'find-one' + ) + ) + def get_row_detail_uri( self, project: NocoDBProject, table: str, row_id: int ): diff --git a/nocodb/infra/requests_client.py b/nocodb/infra/requests_client.py index fd223ed..e14cda8 100644 --- a/nocodb/infra/requests_client.py +++ b/nocodb/infra/requests_client.py @@ -63,6 +63,31 @@ def table_row_delete( self.__api_info.get_row_detail_uri(project, table, row_id), ).json() + def table_count( + self, + project: NocoDBProject, + table: str, + filter_obj: Optional[WhereFilter] = None, + ) -> dict: + return self._request( + "GET", + self.__api_info.get_table_count_uri(project, table), + params=get_query_params(filter_obj), + ).json() + + def table_find_one( + self, + project: NocoDBProject, + table: str, + filter_obj: Optional[WhereFilter] = None, + params: Optional[dict] = None, + ) -> dict: + return self._request( + "GET", + self.__api_info.get_table_find_one_uri(project, table), + params=get_query_params(filter_obj, params), + ).json() + def table_row_nested_relations_list( self, project: NocoDBProject, diff --git a/nocodb/utils.py b/nocodb/utils.py index 4b37cdf..2b98823 100644 --- a/nocodb/utils.py +++ b/nocodb/utils.py @@ -1,4 +1,4 @@ -def get_query_params(filter_obj, params) -> dict: +def get_query_params(filter_obj, params=None) -> dict: query_params = params or {} if filter_obj: query_params["where"] = filter_obj.get_where() diff --git a/setup.py b/setup.py index 750c490..1536887 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='nocodb', - version='0.1.0', + version='0.2.0', author='Samuel López Saura', author_email='samuellopezsaura@gmail.com', packages=find_packages(),