File tree Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Expand file tree Collapse file tree 4 files changed +61
-0
lines changed Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ A DynamoDB based Eloquent model and Query builder for Laravel.
38
38
* [ Working with Queries] ( #working-with-queries )
39
39
+ [ query() and keyCondition()] ( #query-and-keycondition )
40
40
+ [ keyConditionBetween()] ( #keyconditionbetween )
41
+ + [ Sort order] ( #sort-order )
41
42
* [ Working with Scans] ( #working-with-scans )
42
43
+ [ scan()] ( #scan )
43
44
* [ Filtering the Results] ( #filtering-the-results )
@@ -559,6 +560,17 @@ $response = DB::table('Thread')
559
560
->query();
560
561
```
561
562
563
+ #### Sort order
564
+
565
+ ` query ` results are always sorted by the sort key value. To reverse the order, set the ` ScanIndexForward ` parameter to ` false ` .
566
+
567
+ ``` php
568
+ $response = DB::table('Thread')
569
+ ->keyCondition('ForumName', '=', 'Amazon DynamoDB')
570
+ ->scanIndexForward(false)
571
+ ->query();
572
+ ```
573
+
562
574
### Working with Scans
563
575
564
576
#### scan()
Original file line number Diff line number Diff line change @@ -42,6 +42,11 @@ class Builder extends BaseBuilder
42
42
'remove ' => []
43
43
];
44
44
45
+ /**
46
+ * ScanIndexForward option.
47
+ */
48
+ public $ scan_index_forward ;
49
+
45
50
/**
46
51
* LastEvaluatedKey option.
47
52
* @var array|null
@@ -153,6 +158,19 @@ public function key(array $key)
153
158
return $ this ;
154
159
}
155
160
161
+ /**
162
+ * Set the ScanIndexForward option.
163
+ *
164
+ * @param bool $bool
165
+ * @return $this
166
+ */
167
+ public function scanIndexForward ($ bool )
168
+ {
169
+ $ this ->scan_index_forward = $ bool ;
170
+
171
+ return $ this ;
172
+ }
173
+
156
174
/**
157
175
* Set the ExclusiveStartKey option.
158
176
*
@@ -523,6 +541,7 @@ protected function process($query_method, $processor_method)
523
541
$ this ->grammar ->compileItem ($ this ->item ),
524
542
$ this ->grammar ->compileUpdates ($ this ->updates ),
525
543
$ this ->grammar ->compileDynamodbLimit ($ this ->limit ),
544
+ $ this ->grammar ->compileScanIndexForward ($ this ->scan_index_forward ),
526
545
$ this ->grammar ->compileExclusiveStartKey ($ this ->exclusive_start_key ),
527
546
$ this ->grammar ->compileConsistentRead ($ this ->consistent_read ),
528
547
$ this ->grammar ->compileExpressionAttributes ($ this ->expression_attributes )
Original file line number Diff line number Diff line change @@ -152,6 +152,17 @@ public function compileDynamodbLimit($limit)
152
152
];
153
153
}
154
154
155
+ public function compileScanIndexForward ($ bool )
156
+ {
157
+ if (is_null ($ bool )) {
158
+ return [];
159
+ }
160
+
161
+ return [
162
+ 'ScanIndexForward ' => $ bool
163
+ ];
164
+ }
165
+
155
166
public function compileExclusiveStartKey ($ key )
156
167
{
157
168
if (empty ($ key )) {
Original file line number Diff line number Diff line change @@ -108,6 +108,25 @@ public function it_can_set_limit()
108
108
$ this ->assertEquals ($ params , $ query ['params ' ]);
109
109
}
110
110
111
+ /** @test */
112
+ public function it_can_set_scan_index_forward ()
113
+ {
114
+ $ params = [
115
+ 'TableName ' => 'ProductCatalog ' ,
116
+ 'ScanIndexForward ' => false ,
117
+ 'Key ' => [
118
+ 'Id ' => [
119
+ 'N ' => '101 '
120
+ ]
121
+ ]
122
+ ];
123
+ $ query = $ this ->newQuery ('ProductCatalog ' )
124
+ ->scanIndexForward (false )
125
+ ->getItem (['Id ' => 101 ]);
126
+
127
+ $ this ->assertEquals ($ params , $ query ['params ' ]);
128
+ }
129
+
111
130
/** @test */
112
131
public function it_can_set_exclusive_start_key ()
113
132
{
You can’t perform that action at this time.
0 commit comments