Skip to content

Commit f0bb443

Browse files
committed
Change response format.
We need meta data like LastEvaluatedKey for future use.
1 parent 33a5c25 commit f0bb443

File tree

2 files changed

+43
-49
lines changed

2 files changed

+43
-49
lines changed

README.md

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -113,14 +113,14 @@ $response = DB::table('ProductCatalog')
113113
#### PutItem
114114

115115
```php
116-
$item = DB::table('Thread')
117-
->putItem([
118-
'ForumName' => 'Amazon DynamoDB',
119-
'Subject' => 'New discussion thread',
120-
'Message' => 'First post in this thread',
121-
'LastPostedBy' => '[email protected]',
122-
'LastPostedDateTime' => '201603190422'
123-
]);
116+
$response = DB::table('Thread')
117+
->putItem([
118+
'ForumName' => 'Amazon DynamoDB',
119+
'Subject' => 'New discussion thread',
120+
'Message' => 'First post in this thread',
121+
'LastPostedBy' => '[email protected]',
122+
'LastPostedDateTime' => '201603190422'
123+
]);
124124
```
125125

126126
#### UpdateItem
@@ -171,9 +171,9 @@ DB::table('Thread')
171171
Use `select` clause for Projection Expressions.
172172

173173
```php
174-
$item = DB::table('ProductCatalog')
175-
->select('Price', 'Title')
176-
->getItem(['Id' => 101]);
174+
$response = DB::table('ProductCatalog')
175+
->select('Price', 'Title')
176+
->getItem(['Id' => 101]);
177177
```
178178

179179
### Condition Expressions
@@ -227,23 +227,23 @@ DB::table('ProductCatalog')
227227
Use `keyCondition` clause to build Key Conditions.
228228

229229
```php
230-
$items = DB::table('Thread')
231-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
232-
->query();
230+
$response = DB::table('Thread')
231+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
232+
->query();
233233
```
234234

235235
```php
236-
$items = DB::table('Thread')
237-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
238-
->keyCondition('Subject', '=', 'DynamoDB Thread 1')
239-
->query();
236+
$response = DB::table('Thread')
237+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
238+
->keyCondition('Subject', '=', 'DynamoDB Thread 1')
239+
->query();
240240
```
241241

242242
```php
243-
$items = DB::table('Reply')
244-
->keyCondition('Id', '=', 'Amazon DynamoDB#DynamoDB Thread 1')
245-
->keyCondition('ReplyDateTime', 'begins_with', '2015-09')
246-
->query();
243+
$response = DB::table('Reply')
244+
->keyCondition('Id', '=', 'Amazon DynamoDB#DynamoDB Thread 1')
245+
->keyCondition('ReplyDateTime', 'begins_with', '2015-09')
246+
->query();
247247
```
248248

249249
#### Filter Expressions for Query
@@ -253,11 +253,11 @@ Use `filter` clause to build Filter Conditions.
253253
For `query`, KeyConditionExprssion is required, so we specify both KeyConditionExpression and FilterExpression.
254254

255255
```php
256-
$itmes = DB::table('Thread')
257-
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
258-
->keyCondition('Subject', '=', 'DynamoDB Thread 1')
259-
->filter('Views', '>', 3)
260-
->query();
256+
$response = DB::table('Thread')
257+
->keyCondition('ForumName', '=', 'Amazon DynamoDB')
258+
->keyCondition('Subject', '=', 'DynamoDB Thread 1')
259+
->filter('Views', '>', 3)
260+
->query();
261261
```
262262

263263
### Working with Scans in DynamoDB
@@ -267,9 +267,9 @@ $itmes = DB::table('Thread')
267267
#### Filter Expressions for Scan
268268

269269
```php
270-
$items = DB::table('Thread')
271-
->filter('LastPostedBy', '=', 'User A')
272-
->scan();
270+
$response = DB::table('Thread')
271+
->filter('LastPostedBy', '=', 'User A')
272+
->scan();
273273
```
274274

275275
### Using Global Secondary Indexes in DynamoDB
@@ -281,11 +281,11 @@ $items = DB::table('Thread')
281281
Use `index` clause to specify IndexName.
282282

283283
```php
284-
$items = DB::table('Reply')
285-
->index('PostedBy-Message-index')
286-
->keyCondition('PostedBy', '=', 'User A')
287-
->keyCondition('Message', '=', 'DynamoDB Thread 2 Reply 1 text')
288-
->query();
284+
$response = DB::table('Reply')
285+
->index('PostedBy-Message-index')
286+
->keyCondition('PostedBy', '=', 'User A')
287+
->keyCondition('Message', '=', 'DynamoDB Thread 2 Reply 1 text')
288+
->query();
289289
```
290290

291291
## Authentication (Custom User Provider)
@@ -406,7 +406,7 @@ class AuthUserProvider implements BaseUserProvider
406406
*/
407407
public function retrieveById($identifier)
408408
{
409-
$item = DB::table('User')->getItem(['id' => $identifier]);
409+
$item = DB::table('User')->getItem(['id' => $identifier])['Item'];
410410

411411
return new User($item);
412412
}

src/Kitar/Dynamodb/Query/Processor.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,23 @@ public function __construct()
1818

1919
public function processSingleItem(Result $res)
2020
{
21-
$item = $res['Item'];
21+
$responseArray = $res->toArray();
2222

23-
if (empty($item)) {
24-
return null;
23+
if (! empty($responseArray['Item'])) {
24+
$responseArray['Item'] = $this->marshaler->unmarshalItem($responseArray['Item']);
2525
}
2626

27-
return new Collection(
28-
$this->marshaler->unmarshalItem($item)
29-
);
27+
return $responseArray;
3028
}
3129

3230
public function processMultipleItems(Result $res)
3331
{
34-
$items = $res['Items'];
32+
$responseArray = $res->toArray();
3533

36-
if (empty($items)) {
37-
return [];
38-
}
39-
40-
foreach ($items as &$item) {
34+
foreach ($responseArray['Items'] as &$item) {
4135
$item = $this->marshaler->unmarshalItem($item);
4236
}
4337

44-
return $items;
38+
return $responseArray;
4539
}
4640
}

0 commit comments

Comments
 (0)