Skip to content

Commit e29ad04

Browse files
committed
add document for batch operations
1 parent 7b5a7af commit e29ad04

File tree

1 file changed

+85
-6
lines changed

1 file changed

+85
-6
lines changed

README.md

+85-6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ You can find an example implementation in [kitar/simplechat](https://github.com/
5353
* [Using Global Secondary Indexes](#using-global-secondary-indexes)
5454
+ [index()](#index)
5555
* [Atomic Counter](#atomic-counter)
56+
* [Batch Operations](#batch-operations)
57+
+ [batchGetItem()](#batchgetitem)
58+
+ [batchPutItem()](#batchputitem)
59+
+ [batchDeleteItem()](#batchdeleteitem)
60+
+ [batchWriteItem()](#batchwriteitem)
5661
* [DynamoDB-specific operators for condition() and filter()](#dynamodb-specific-operators-for-condition-and-filter)
5762
+ [Comparators](#comparators)
5863
+ [functions](#functions)
@@ -197,7 +202,6 @@ class User extends Model implements AuthenticatableContract
197202
}
198203
```
199204

200-
> **Note**
201205
> Note that this model is implementing `Illuminate\Contracts\Auth\Authenticatable` and using `Illuminate\Auth\Authenticatable`. This is **optional**, but if we use them, we can use this model with authentication as well. For authentication, please refer to [Authentication section](#authentication-with-model)) for more details.
202206
203207
### Basic Usage
@@ -234,7 +238,6 @@ public static function scan($exclusiveStartKey = null, $sort = 'asc', $limit = 5
234238
}
235239
```
236240

237-
> **Note**
238241
> 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.
239242
240243
#### Retrieving a model
@@ -474,7 +477,6 @@ $response = DB::table('ProductCatalog')
474477
->getItem(['Id' => 101]);
475478
```
476479

477-
> **Note**
478480
> Instead of marshaling manually, pass a plain array. `Kitar\Dynamodb\Query\Grammar` will automatically marshal them before querying.
479481
480482
#### putItem()
@@ -547,7 +549,6 @@ DB::table('ProductCatalog')
547549
]);
548550
```
549551

550-
> **Note**
551552
> Note that we specify `attribute_not_exists` for the operator of condition. This is DynamoDB-specific operator which called `function`. See [DynamoDB-specific operators for condition() and filter()](#dynamodb-specific-operators-for-condition-and-filter) for more details.
552553
553554
OR statements
@@ -625,7 +626,6 @@ $response = DB::table('Thread')
625626
->query();
626627
```
627628

628-
> **Note**
629629
> Note that DynamoDB's `ScanIndexForward` is a feature for `query`. It will not work with `scan`.
630630
631631
### Working with Scans
@@ -755,6 +755,86 @@ DB::('Thread')->key([
755755
]);
756756
```
757757

758+
### Batch Operations
759+
760+
Batch operations can get, put or delete multiple items with a single call. There are some DynamoDB limitations (such as items count, payload size, etc), so please check the documentation in advance. ([BatchGetItem](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchGetItem.html), [BatchWriteItem](https://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_BatchWriteItem.html))
761+
762+
#### batchGetItem()
763+
764+
```php
765+
DB::table('Thread')
766+
->batchGetItem([
767+
[
768+
'ForumName' => 'Amazon DynamoDB',
769+
'Subject' => 'DynamoDB Thread 1'
770+
],
771+
[
772+
'ForumName' => 'Amazon DynamoDB',
773+
'Subject' => 'DynamoDB Thread 2'
774+
]
775+
]);
776+
```
777+
778+
#### batchPutItem()
779+
780+
```php
781+
DB::table('Thread')
782+
->batchPutItem([
783+
[
784+
'ForumName' => 'Amazon DynamoDB',
785+
'Subject' => 'DynamoDB Thread 3'
786+
],
787+
[
788+
'ForumName' => 'Amazon DynamoDB',
789+
'Subject' => 'DynamoDB Thread 4'
790+
]
791+
]);
792+
```
793+
794+
> This is a handy method to batch-put items using `batchWriteItem`
795+
796+
#### batchDeleteItem()
797+
798+
```php
799+
DB::table('Thread')
800+
->batchDeleteItem([
801+
[
802+
'ForumName' => 'Amazon DynamoDB',
803+
'Subject' => 'DynamoDB Thread 1'
804+
],
805+
[
806+
'ForumName' => 'Amazon DynamoDB',
807+
'Subject' => 'DynamoDB Thread 2'
808+
]
809+
]);
810+
```
811+
812+
> This is a handy method to batch-delete items using `batchWriteItem`
813+
814+
#### batchWriteItem()
815+
816+
```php
817+
DB::table('Thread')
818+
->batchWriteItem([
819+
[
820+
'PutRequest' => [
821+
'Item' => [
822+
'ForumName' => 'Amazon DynamoDB',
823+
'Subject' => 'DynamoDB Thread 3'
824+
]
825+
]
826+
],
827+
[
828+
'DeleteRequest' => [
829+
'Key' => [
830+
'ForumName' => 'Amazon DynamoDB',
831+
'Subject' => 'DynamoDB Thread 1'
832+
]
833+
]
834+
]
835+
]);
836+
```
837+
758838
### DynamoDB-specific operators for condition() and filter()
759839

760840
For `condition` and `filter` clauses, we can use DynamoDB's comparators and functions.
@@ -779,7 +859,6 @@ filter($key, 'begins_with', $value);
779859
filter($key, 'contains', $value);
780860
```
781861

782-
> **Note**
783862
> `size` function is not supported at this time.
784863
785864
## Testing

0 commit comments

Comments
 (0)