Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Supports all key types - primary hash key and composite keys.
* [save](#save) / [saveAsync()](#saveasync)
* [delete](#delete) / [deleteAsync()](#deleteasync)
* [chunk](#chunk)
* [pagedCount](#pagedcount)
* [limit() and take()](#limit-and-take)
* [firstOrFail()](#firstorfail)
* [findOrFail()](#findorfail)
Expand Down Expand Up @@ -277,6 +278,19 @@ $model->chunk(10, function ($records) {
});
```

#### pagedCount()

```php
$countResult = $model->pagedCount();
if($countResult->lastKey) {
//lastEvaluatedKey is already set to $model
//$countResultNext will contain counts from next page
$countResultNext = $model->pagedCount();
//...
}

```

#### limit() and take()

```php
Expand Down
16 changes: 16 additions & 0 deletions src/DynamoDbQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,22 @@ public function count()

return $res['Count'];
}

public function pagedCount()
{
$limit = isset($this->limit) ? $this->limit : static::MAX_LIMIT;

$raw = $this->toDynamoDbQuery(['count(*)'], $limit);

if ($raw->op === 'Scan') {
$res = $this->client->scan($raw->query);
} else {
$res = $this->client->query($raw->query);
}
$this->lastEvaluatedKey = Arr::get($res, 'LastEvaluatedKey');

return (object)['count' => $res['Count'], 'scanned_count' => $res['ScannedCount'], 'lastKey' => $this->lastEvaluatedKey];
}

public function decorate(Closure $closure)
{
Expand Down