Skip to content

Commit

Permalink
Add document for Atomic Counter
Browse files Browse the repository at this point in the history
  • Loading branch information
kitar committed Mar 22, 2021
1 parent 58888db commit d8ec1a7
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ A DynamoDB based Eloquent model and Query builder for Laravel.
+ [save()](#save)
+ [update()](#update)
+ [delete()](#delete)
+ [increment() / decrement()](#increment-/-decrement)
* [Advanced Queries](#advanced-queries)
- [Authentication with model](#authentication-with-model)
* [Register custom user provider](#register-custom-user-provider)
Expand Down Expand Up @@ -47,6 +48,7 @@ A DynamoDB based Eloquent model and Query builder for Laravel.
+ [exclusiveStartKey()](#exclusivestartkey)
* [Using Global Secondary Indexes](#using-global-secondary-indexes)
+ [index()](#index)
* [Atomic Counter](#atomic-counter)
* [DynamoDB-specific operators for condition() and filter()](#dynamodb-specific-operators-for-condition-and-filter)
+ [Comparators](#comparators)
+ [functions](#functions)
Expand Down Expand Up @@ -252,6 +254,23 @@ $user->update([
$user->delete();
```

#### increment() / decrement()

When we call `increment()` and `decrement()`, the [Atomic Counter](#atomic-counter) will be used under the hood.

```php
$user->increment('views', 1);
$user->decrement('views', 1);
```

We can also pass additional attributes to update.

```php
$user->increment('views', 1, [
'last_viewed_at' => '...',
]);
```

### Advanced Queries
We can use Query Builder functions through model such as `query` `scan` `filter` `condition` `keyCondition` etc.

Expand Down Expand Up @@ -638,6 +657,28 @@ $response = DB::table('Reply')
->query();
```

### Atomic Counter

DynamoDB [supports Atomic Counter](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/WorkingWithItems.html#WorkingWithItems.AtomicCounters). When we call `increment()` and `decrement()` through Model or Query Builder, Atomic Counter will be used under the hood.

```php
DB::('Thread')->key([
'ForumName' => 'Laravel',
'Subject' => 'Laravel Thread 1'
])->increment('Replies', 2);
```

We can also pass additional attributes to update.

```php
DB::('Thread')->key([
'ForumName' => 'Laravel',
'Subject' => 'Laravel Thread 1'
])->increment('Replies', 2, [
'LastPostedBy' => 'User A',
]);
```

### DynamoDB-specific operators for condition() and filter()

For `condition` and `filter` clauses, we can use DynamoDB's comparators and functions.
Expand Down

0 comments on commit d8ec1a7

Please sign in to comment.