Skip to content

Commit af6180a

Browse files
committed
Update README.md according to #40
1 parent cdcfef6 commit af6180a

File tree

1 file changed

+59
-59
lines changed

1 file changed

+59
-59
lines changed

README.md

+59-59
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ $connection->table('your-table')->...
129129

130130
## Sample data
131131

132-
Many of the example codes in this document are querying to [DynamoDB's official sample data](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/SampleData.LoadData.html). If you want to try these codes with actual DynamoDB tables, it's handy to load them to your tables before.
132+
Many of the example codes in this document are querying to [DynamoDB's official sample data](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/AppendixSampleTables.html). If you want to try these codes with actual DynamoDB tables, it's handy to load them to your tables before.
133133

134134
## Model
135135

@@ -224,18 +224,13 @@ You also can override the `scan()` method to fit your needs, such as filtering m
224224
```php
225225
public static function scan($exclusiveStartKey = null, $sort = 'asc', $limit = 50)
226226
{
227-
$products = static::index('GSI1')
228-
->keyCondition('GSI1PK', '=', 'PRODUCT#')
229-
->keyCondition('GSI1SK', 'begins_with', 'PRODUCT#')
230-
->exclusiveStartKey($exclusiveStartKey)
231-
->scanIndexForward($sort == 'desc' ? false : true)
232-
->limit($limit)
233-
->query();
234-
235-
return [
236-
'items' => $products,
237-
'LastEvaluatedKey' => $products->first()->meta()['LastEvaluatedKey'] ?? null,
238-
];
227+
return static::index('GSI1')
228+
->keyCondition('GSI1PK', '=', 'PRODUCT#')
229+
->keyCondition('GSI1SK', 'begins_with', 'PRODUCT#')
230+
->exclusiveStartKey($exclusiveStartKey)
231+
->scanIndexForward($sort == 'desc' ? false : true)
232+
->limit($limit)
233+
->query();
239234
}
240235
```
241236

@@ -339,16 +334,16 @@ For example:
339334

340335
```php
341336
Thread::keyCondition('ForumName', '=', 'Amazon DynamoDB')
342-
->keyCondition('Subject', 'begins_with', 'DynamoDB')
343-
->filter('Views', '=', 0)
344-
->query();
337+
->keyCondition('Subject', 'begins_with', 'DynamoDB')
338+
->filter('Views', '=', 0)
339+
->query();
345340
```
346341

347342
Please refer to [Query Builder](#query-builder) for the details.
348343

349344
## Authentication with model
350345

351-
We can create a Custom User Provider to authenticate with DynamoDB. For the detail, please refer to [Laravel's official document](https://laravel.com/docs/8.x/authentication#adding-custom-user-providers).
346+
We can create a Custom User Provider to authenticate with DynamoDB. For the detail, please refer to [Laravel's official document](https://laravel.com/docs/authentication#adding-custom-user-providers).
352347

353348
To use authentication with the model, the model should implement `Illuminate\Contracts\Auth\Authenticatable` contract. In this section, we'll use the example `User` model above.
354349

@@ -460,7 +455,6 @@ $connection = new Kitar\Dynamodb\Connection([
460455
]);
461456

462457
$result = $connection->table('Thread')->scan();
463-
464458
```
465459

466460
If we query through the model, we don't need to specify the table name, and the response will be the model instance(s).
@@ -475,7 +469,7 @@ $threads = Thread::scan();
475469

476470
```php
477471
$response = DB::table('ProductCatalog')
478-
->getItem(['Id' => 101]);
472+
->getItem(['Id' => 101]);
479473
```
480474

481475
> Instead of marshaling manually, pass a plain array. `Kitar\Dynamodb\Query\Grammar` will automatically marshal them before querying.
@@ -529,8 +523,8 @@ We can specify Projection Expressions in the same manner as the original `select
529523

530524
```php
531525
$response = DB::table('ProductCatalog')
532-
->select('Price', 'Title')
533-
->getItem(['Id' => 101]);
526+
->select('Price', 'Title')
527+
->getItem(['Id' => 101]);
534528
```
535529

536530
### Condition Expressions
@@ -574,20 +568,20 @@ DB::table('ProductCatalog')
574568

575569
```php
576570
ProductCatalog::key(['Id' => 101])
577-
->conditionIn('ProductCategory', ['Book', 'Bicycle'])
578-
->updateItem([
579-
'Description' => 'updated!'
580-
]);
571+
->conditionIn('ProductCategory', ['Book', 'Bicycle'])
572+
->updateItem([
573+
'Description' => 'updated!'
574+
]);
581575
```
582576

583577
#### conditionBetween()
584578

585579
```php
586580
ProductCatalog::key(['Id' => 101])
587-
->conditionBetween('Price', [0, 10])
588-
->updateItem([
589-
'Description' => 'updated!'
590-
]);
581+
->conditionBetween('Price', [0, 10])
582+
->updateItem([
583+
'Description' => 'updated!'
584+
]);
591585
```
592586

593587
### Working with Queries
@@ -602,18 +596,18 @@ We can use some comparison operators for sort key, but we must use the equality
602596

603597
```php
604598
$response = DB::table('Thread')
605-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
606-
->keyCondition('Subject', 'begins_with', 'DynamoDB')
607-
->query();
599+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
600+
->keyCondition('Subject', 'begins_with', 'DynamoDB')
601+
->query();
608602
```
609603

610604
#### keyConditionBetween()
611605

612606
```php
613607
$response = DB::table('Thread')
614-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
615-
->keyConditionBetween('Subject', ['DynamoDB Thread 1', 'DynamoDB Thread 2'])
616-
->query();
608+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
609+
->keyConditionBetween('Subject', ['DynamoDB Thread 1', 'DynamoDB Thread 2'])
610+
->query();
617611
```
618612

619613
#### Sort order
@@ -622,9 +616,9 @@ $response = DB::table('Thread')
622616

623617
```php
624618
$response = DB::table('Thread')
625-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
626-
->scanIndexForward(false)
627-
->query();
619+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
620+
->scanIndexForward(false)
621+
->query();
628622
```
629623

630624
> Note that DynamoDB's `ScanIndexForward` is a feature for `query`. It will not work with `scan`.
@@ -647,42 +641,42 @@ It can't reduce the amount of read capacity, but it can reduce the size of traff
647641

648642
```php
649643
$response = DB::table('Thread')
650-
->filter('LastPostedBy', '=', 'User A')
651-
->scan();
644+
->filter('LastPostedBy', '=', 'User A')
645+
->scan();
652646
```
653647

654648
OR statement
655649

656650
```php
657651
$response = DB::table('Thread')
658-
->filter('LastPostedBy', '=', 'User A')
659-
->orFilter('LastPostedBy', '=', 'User B')
660-
->scan();
652+
->filter('LastPostedBy', '=', 'User A')
653+
->orFilter('LastPostedBy', '=', 'User B')
654+
->scan();
661655
```
662656

663657
AND statement
664658

665659
```php
666660
$response = DB::table('Thread')
667-
->filter('LastPostedBy', '=', 'User A')
668-
->filter('Subject', 'begins_with', 'DynamoDB')
669-
->scan();
661+
->filter('LastPostedBy', '=', 'User A')
662+
->filter('Subject', 'begins_with', 'DynamoDB')
663+
->scan();
670664
```
671665

672666
#### filterIn()
673667

674668
```php
675669
$response = DB::table('Thread')
676-
->filterIn('LastPostedBy', ['User A', 'User B'])
677-
->scan();
670+
->filterIn('LastPostedBy', ['User A', 'User B'])
671+
->scan();
678672
```
679673

680674
#### filterBetween()
681675

682676
```php
683677
$response = DB::table('ProductCatalog')
684-
->filterBetween('Price', [0, 100])
685-
->scan();
678+
->filterBetween('Price', [0, 100])
679+
->scan();
686680
```
687681

688682
### Paginating the Results
@@ -695,8 +689,8 @@ If there are more results, the response contains `LastEvaluatedKey`.
695689

696690
```php
697691
$response = DB::table('ProductCatalog')
698-
->limit(5)
699-
->scan();
692+
->limit(5)
693+
->scan();
700694

701695
$response['LastEvaluatedKey']; // array
702696
```
@@ -705,16 +699,22 @@ We can pass this key to `exclusiveStartKey` to get next results.
705699

706700
```php
707701
$response = DB::table('ProductCatalog')
708-
->exclusiveStartKey($response['LastEvaluatedKey'])
709-
->limit(5)
710-
->scan();
702+
->exclusiveStartKey($response['LastEvaluatedKey'])
703+
->limit(5)
704+
->scan();
711705
```
712706

713707
If you are using Query Builder through model, you can access to `exclusiveStartKey` by:
714708

715709
```php
716710
$products = ProductCatalog::limit(5)->scan();
717711

712+
$products->getLastEvaluatedKey(); // array
713+
```
714+
715+
Alternatively, you can achieve the same result using individual models; however, please be aware that this approach is planned to be deprecated in versions subsequent to v2.x.
716+
717+
```php
718718
$products->first()->meta()['LastEvaluatedKey']; // array
719719
```
720720

@@ -728,10 +728,10 @@ Use `index` clause to specify Global Secondary Index name.
728728

729729
```php
730730
$response = DB::table('Reply')
731-
->index('PostedBy-Message-index')
732-
->keyCondition('PostedBy', '=', 'User A')
733-
->keyCondition('Message', '=', 'DynamoDB Thread 2 Reply 1 text')
734-
->query();
731+
->index('PostedBy-Message-index')
732+
->keyCondition('PostedBy', '=', 'User A')
733+
->keyCondition('Message', '=', 'DynamoDB Thread 2 Reply 1 text')
734+
->query();
735735
```
736736

737737
### Atomic Counter

0 commit comments

Comments
 (0)