Skip to content

Commit

Permalink
Add documentation for query.withCount
Browse files Browse the repository at this point in the history
  • Loading branch information
dplewis committed Jul 23, 2019
1 parent 4973012 commit 17be338
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion _includes/js/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ query.withCount();
const response = await query.find(); // { results: [ GameScore, ... ], count: 200 }
```
⚠️ Сount operations can be slow and expensive.
> If you only want to get the count without objects - use [Counting Objects](#counting-objects).

If you only want to get the count without objects - use [Counting Objects](#counting-objects).

For sortable types like numbers and strings, you can control the order in which results are returned:

Expand Down
26 changes: 26 additions & 0 deletions _includes/php/queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,32 @@ You can skip the first results by setting `skip`. In the old Parse hosted backen
$query->skip(10); // skip the first 10 results
```

### With Count

If you want to know the total number of rows in a table satisfying your query, for e.g. pagination purposes - you can use `withCount`.

**Note:** Using this feature will change the structure of response, see the example below.

Let's say you have 200 rows in a table called `GameScore`:

```php
$query = new ParseQuery('GameScore');
$query->withCount();
$query->limit(25);

$response = $query->find();
$response['count'] // Returns 200 the total number of objects dispite limit / skip
$response['results'] // Returns 25 objects

// As of PHP 7.1 you can use Array Destructuring
['count' => $count, 'results' => $results] = $query->find();

// Use $count and $results
```
⚠️ Сount operations can be slow and expensive.

If you only want to get the count without objects - use [Counting Objects](#counting-objects).

### Ascending and Descending

For sortable types like numbers and strings, you can control the order in which results are returned:
Expand Down

0 comments on commit 17be338

Please sign in to comment.