@@ -27,7 +27,8 @@ Supports all key types - primary hash key and composite keys.
2727 * [ findOrFail()] ( #findorfail )
2828 * [ Query scope] ( #query-scope )
2929 * [ REMOVE — Deleting Attributes From An Item] ( #remove--deleting-attributes-from-an-item )
30- * [ toSql() style] ( #tosql-style )
30+ * [ toSql() Style] ( #tosql-style )
31+ * [ Decorate Query] ( #decorate-query )
3132* [ Indexes] ( #indexes )
3233* [ Composite Keys] ( #composite-keys )
3334* [ Requirements] ( #requirements )
@@ -258,19 +259,49 @@ Model::find('foo')->removeAttribute('name', 'description', 'nested.foo', 'nested
258259```
259260
260261
261- #### toSql() style
262+ #### toSql() Style
262263
263264For debugging purposes, you can choose to convert to the actual DynamoDb query
264265
265266```php
266267$raw = $model->where(' count' , ' > ' , 10)->toDynamoDbQuery();
268+ // $op is either "Scan" or "Query"
267269$op = $raw->op;
270+ // The query body being sent to AWS
268271$query = $raw->query;
269272```
270273
271- where `$op` will be either `Scan` or `Query` and `$query` will be the query body being sent to AWS.
274+ where `$raw` is an instance of [RawDynamoDbQuery](./src/RawDynamoDbQuery.php)
272275
273276
277+ #### Decorate Query
278+
279+ Use `decorate` when you want to enhance the query. For example:
280+
281+ To set the order of the sort key:
282+
283+ ```php
284+ $items = $model
285+ ->where(' hash' , ' hash-value' )
286+ ->where(' range' , ' > ' , 10)
287+ ->decorate(function (RawDynamoDbQuery $raw) {
288+ // desc order
289+ $raw->query[' ScanIndexForward' ] = false;
290+ })
291+ ->get();
292+ ```
293+
294+ To force to use "Query" instead of "Scan" if the library fails to detect the correct operation:
295+
296+ ```php
297+ $items = $model
298+ ->where(' hash' , ' hash-value' )
299+ ->decorate(function (RawDynamoDbQuery $raw) {
300+ $raw->op = ' Query' ;
301+ })
302+ ->get();
303+ ```
304+
274305Indexes
275306-----------
276307If your table has indexes, make sure to declare them in your model class like so
0 commit comments