Skip to content

Commit 48ca40b

Browse files
Merge pull request #25 from SlicingDice/feature/update-count_total-method
Update count_entity_total method and README example
2 parents 69b5835 + 578cc1f commit 48ca40b

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

README.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,13 +263,14 @@ print client.exists_entity(ids)
263263
```
264264

265265
### `count_entity_total()`
266-
Count the number of inserted entities. This method corresponds to a [GET request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
266+
Count the number of inserted entities in the whole database. This method corresponds to a [POST request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
267267

268268
#### Request example
269269

270270
```python
271271
from pyslicer import SlicingDice
272272
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
273+
273274
print client.count_entity_total()
274275
```
275276

@@ -285,6 +286,32 @@ print client.count_entity_total()
285286
}
286287
```
287288

289+
### `count_entity_total(tables)`
290+
Count the total number of inserted entities in the given tables. This method corresponds to a [POST request at /query/count/entity/total](http://panel.slicingdice.com/docs/#api-details-api-endpoints-get-query-count-entity-total).
291+
292+
#### Request example
293+
294+
```python
295+
from pyslicer import SlicingDice
296+
client = SlicingDice('MASTER_OR_READ_API_KEY', uses_test_endpoint=False)
297+
298+
tables = ['default']
299+
300+
print client.count_entity_total(tables)
301+
```
302+
303+
#### Output example
304+
305+
```json
306+
{
307+
"status": "success",
308+
"result": {
309+
"total": 42
310+
},
311+
"took": 0.103
312+
}
313+
```
314+
288315
### `count_entity(json_data)`
289316
Count the number of entities matching the given query. This method corresponds to a [POST request at /query/count/entity](http://panel.slicingdice.com/docs/#api-details-api-endpoints-post-query-count-entity).
290317

pyslicer/client.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,22 @@ def count_entity(self, query):
213213
url = base_url + URLResources.QUERY_COUNT_ENTITY
214214
return self._count_query_wrapper(url, query)
215215

216-
def count_entity_total(self):
217-
"""Make a count entity total query"""
216+
def count_entity_total(self, tables=[]):
217+
"""Make a count entity total query
218+
219+
Keyword arguments:
220+
tables -- A dictionary containing the tables in which
221+
the total query will be performed
222+
"""
223+
query = {
224+
'tables': tables
225+
}
218226
base_url = self._wrapper_test()
219227
url = base_url + URLResources.QUERY_COUNT_ENTITY_TOTAL
220228
return self._make_request(
221229
url=url,
222-
req_type="get",
230+
req_type="post",
231+
json_data=ujson.dumps(query),
223232
key_level=0)
224233

225234
def count_event(self, query):

0 commit comments

Comments
 (0)