Skip to content

Commit f5d7439

Browse files
committed
update readme
related to #14
1 parent e5ef769 commit f5d7439

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,26 @@ or alternatively,
205205
$products = ProductCatalog::all();
206206
```
207207

208+
You also can override the `scan()` method to fit your needs, such as filtering models for single table design. For example:
209+
210+
```php
211+
public static function scan($exclusiveStartKey = null, $sort = 'asc', $limit = 50)
212+
{
213+
$products = static::index('GSI1')
214+
->keyCondition('GSI1PK', '=', 'PRODUCT#')
215+
->keyCondition('GSI1SK', 'begins_with', 'PRODUCT#')
216+
->exclusiveStartKey($exclusiveStartKey)
217+
->scanIndexForward($sort == 'desc' ? false : true)
218+
->limit($limit)
219+
->query();
220+
221+
return [
222+
'items' => $products,
223+
'LastEvaluatedKey' => $products->first()->meta()['LastEvaluatedKey'] ?? null,
224+
];
225+
}
226+
```
227+
208228
> DynamoDB can only handle result set up to 1MB per call, so we have to paginate if there are more results. see [Paginating the Results](#paginating-the-results) for more details.
209229
210230
#### Retrieving a model
@@ -230,6 +250,18 @@ If the model has sort key and `sortKeyDefault` is defined:
230250
User::find('[email protected]'); // Partition key. sortKeyDefault will be used for Sort key.
231251
```
232252

253+
You also can modify the behavior of the `find()` method to fit your needs. For example:
254+
255+
```php
256+
public static function find($userId)
257+
{
258+
return parent::find([
259+
'PK' => str_starts_with($userId, 'USER#') ? $userId : 'USER#'.$userId,
260+
'SK' => 'USER#',
261+
]);
262+
}
263+
```
264+
233265
#### create()
234266

235267
```php

0 commit comments

Comments
 (0)