Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3dd40a3

Browse files
deanmalanelchicodepython
andcommitted
Add count and find-one methods (elchicodepython#6)
* Raise exception for unsuccessful requests * Add request call * Add count * Add find one * Add examples to README.md * Fix README for count Co-authored-by: Samuel López <samuellopezsaura@gmail.com> --------- Co-authored-by: Samuel López <samuellopezsaura@gmail.com>
1 parent ce4535f commit 3dd40a3

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

‎README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@ table_rows = client.table_row_list(project, table_name, params={'offset': 100})
101101
table_rows = client.table_row_list(project, table_name, InFilter("name", "sam"))
102102
table_rows = client.table_row_list(project, table_name, filter_obj=EqFilter("Id", 100))
103103

104+
# Filter and count rows
105+
count = client.table_count(project, table_name, filter_obj=EqFilter("Id", 100))
106+
107+
# Find one row
108+
table_row = client.table_find_one(project, table_name, filter_obj=EqFilter("Id", 100), params={"sort": "-created_at"})
109+
104110
# Retrieve a single row
105111
row_id = 10
106112
row = client.table_row_detail(project, table_name, row_id)

‎nocodb/api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,22 @@ def get_table_uri(self, project: NocoDBProject, table: str) -> str:
2626
)
2727
)
2828

29+
def get_table_count_uri(self, project: NocoDBProject, table: str) -> str:
30+
return "/".join(
31+
(
32+
self.get_table_uri(project, table),
33+
'count'
34+
)
35+
)
36+
37+
def get_table_find_one_uri(self, project: NocoDBProject, table: str) -> str:
38+
return "/".join(
39+
(
40+
self.get_table_uri(project, table),
41+
'find-one'
42+
)
43+
)
44+
2945
def get_row_detail_uri(
3046
self, project: NocoDBProject, table: str, row_id: int
3147
):

‎nocodb/infra/requests_client.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,31 @@ def table_row_delete(self, project: NocoDBProject, table: str, row_id: int) -> i
7878
self.__api_info.get_row_detail_uri(project, table, row_id),
7979
).json()
8080

81+
def table_count(
82+
self,
83+
project: NocoDBProject,
84+
table: str,
85+
filter_obj: Optional[WhereFilter] = None,
86+
) -> dict:
87+
return self._request(
88+
"GET",
89+
self.__api_info.get_table_count_uri(project, table),
90+
params=get_query_params(filter_obj),
91+
).json()
92+
93+
def table_find_one(
94+
self,
95+
project: NocoDBProject,
96+
table: str,
97+
filter_obj: Optional[WhereFilter] = None,
98+
params: Optional[dict] = None,
99+
) -> dict:
100+
return self._request(
101+
"GET",
102+
self.__api_info.get_table_find_one_uri(project, table),
103+
params=get_query_params(filter_obj, params),
104+
).json()
105+
81106
def table_row_nested_relations_list(
82107
self,
83108
project: NocoDBProject,

‎nocodb/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
def get_query_params(filter_obj, params) -> dict:
1+
def get_query_params(filter_obj, params=None) -> dict:
22
query_params = params or {}
33
if filter_obj:
44
query_params["where"] = filter_obj.get_where()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /