Skip to content

Commit 8459407

Browse files
Merge pull request #16 from SlicingDice/feature/update-count_total-method
Update countEntityTotal method and README example
2 parents a76f9dd + 217d12a commit 8459407

File tree

2 files changed

+46
-5
lines changed

2 files changed

+46
-5
lines changed

README.md

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ client.existsEntity(ids).then((resp) => {
308308
```
309309

310310
### `countEntityTotal()`
311-
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).
311+
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).
312312

313313
#### Request example
314314

@@ -339,6 +339,40 @@ client.countEntityTotal().then((resp) => {
339339
}
340340
```
341341

342+
### `countEntityTotal(tables)`
343+
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).
344+
345+
#### Request example
346+
347+
```javascript
348+
let SlicingDice = require('slicerjs');
349+
350+
const client = new SlicingDice({
351+
masterKey: 'MASTER_KEY',
352+
readKey: 'READ_KEY'
353+
}, usesTestEndpoint = true);
354+
355+
const tables = ["default"];
356+
357+
client.countEntityTotal(tables).then((resp) => {
358+
console.log(resp);
359+
}, (err) => {
360+
console.error(err);
361+
});
362+
```
363+
364+
#### Output example
365+
366+
```json
367+
{
368+
"status": "success",
369+
"result": {
370+
"total": 42
371+
},
372+
"took": 0.103
373+
}
374+
```
375+
342376
### `countEntity(jsonData)`
343377
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).
344378

src/slicer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -551,13 +551,20 @@
551551
let sdValidator = new QueryCountValidator(query);
552552
return this.countQueryWrapper(query, path);
553553
}
554-
555-
/* Makes a total query on Slicing Dice API */
556-
countEntityTotal() {
554+
555+
/* Makes a total query on Slicing Dice API
556+
*
557+
* @param (array) tables - the tables in which the total query will be performed
558+
*/
559+
countEntityTotal(tables = []) {
560+
let query = {
561+
"tables": tables
562+
};
557563
let path = this._sdRoutes.countEntityTotal;
558564
return this.makeRequest({
559565
path: path,
560-
reqType: "GET",
566+
reqType: "POST",
567+
data: query,
561568
levelKey: 0
562569
})
563570
}

0 commit comments

Comments
 (0)