Skip to content

Commit 9a804dd

Browse files
authored
Merge pull request #79 from baopham/expression
Upgrade legacy attributes
2 parents 6a22e38 + d02991d commit 9a804dd

13 files changed

+725
-129
lines changed

README.md

+18-13
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,26 @@ $model->delete();
8989
// Using getIterator(). If 'key' is the primary key or a global/local index and the condition is EQ, will use 'Query', otherwise 'Scan'.
9090
$model->where('key', 'key value')->get();
9191
92-
// See BaoPham\DynamoDb\ComparisonOperator
9392
$model->where(['key' => 'key value']);
94-
// Chainable for 'AND'. 'OR' is not supported.
93+
// Chainable for 'AND'. 'OR' is not tested.
9594
$model->where('foo', 'bar')
9695
->where('foo2', '!=' 'bar2')
9796
->get();
97+
$model->where('count', 'between', [0, 100])->get();
98+
$model->where('count', '>', 0)->get();
99+
$model->where('description', 'begins_with', 'foo')->get();
100+
$model->where('description', 'contains', 'foo')->get();
101+
$model->where('description', 'not_contains', 'foo')->get();
102+
```
103+
104+
##### whereNull() and whereNotNull()
105+
106+
> NULL and NOT_NULL only check for the attribute presence not its value being null
107+
> See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
108+
109+
```php
110+
$model->whereNull('name');
111+
$model->whereNotNull('name');
98112
```
99113
100114
#### all() and first()
@@ -161,16 +175,6 @@ $model->findOrFail('foo');
161175
$model->findOrFail(['id' => 'foo', 'id2' => 'bar']);
162176
```
163177
164-
#### whereNull() and whereNotNull()
165-
166-
> NULL and NOT_NULL only check for the attribute presence not its value being null
167-
> See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
168-
169-
```php
170-
$model->whereNull('name');
171-
$model->whereNotNull('name');
172-
```
173-
174178
Indexes
175179
-----------
176180
If your table has indexes, make sure to declare them in your model class like so
@@ -259,7 +263,8 @@ Laravel ^5.1
259263
260264
TODO
261265
----
262-
- [ ] Upgrade a few legacy attributes: `AttributesToGet`, `ScanFilter`, ...
266+
- [ ] Nested conditions
267+
- [ ] Verify OR conditions
263268
264269
FAQ
265270
---

src/ComparisonOperator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ public static function isValidQueryDynamoDbOperator($dynamoDbOperator, $isRangeK
9292
return in_array($dynamoDbOperator, static::getQuerySupportedOperators($isRangeKey));
9393
}
9494

95-
public static function is($op, $opToCompare)
95+
public static function is($op, $dynamoDbOperator)
9696
{
9797
$mapping = static::getOperatorMapping();
98-
return $mapping[strtolower($op)] === $opToCompare;
98+
return $mapping[strtolower($op)] === $dynamoDbOperator;
9999
}
100100
}

src/DynamoDbModel.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,15 @@ abstract class DynamoDbModel extends Model
4040

4141
/**
4242
* Indexes.
43-
* [
44-
* 'global_index_key' => 'global_index_name',
45-
* 'local_index_key' => 'local_index_name',
46-
* ].
43+
* [
44+
* 'simple_index_name' => [
45+
* 'hash' => 'index_key'
46+
* ],
47+
* 'composite_index_name' => [
48+
* 'hash' => 'index_hash_key',
49+
* 'range' => 'index_range_key'
50+
* ],
51+
* ]
4752
*
4853
* @var array
4954
*/
@@ -198,11 +203,7 @@ public static function all($columns = [])
198203
*/
199204
public function newQuery()
200205
{
201-
$builder = new DynamoDbQueryBuilder();
202-
203-
$builder->setModel($this);
204-
205-
$builder->setClient($this->client);
206+
$builder = new DynamoDbQueryBuilder($this);
206207

207208
return $builder;
208209
}
@@ -294,6 +295,14 @@ public function setDynamoDbIndexKeys($dynamoDbIndexKeys)
294295
$this->dynamoDbIndexKeys = $dynamoDbIndexKeys;
295296
}
296297

298+
/**
299+
* @return \Aws\DynamoDb\Marshaler
300+
*/
301+
public function getMarshaler()
302+
{
303+
return $this->marshaler;
304+
}
305+
297306
/**
298307
* Remove non-serializable properties when serializing.
299308
*

0 commit comments

Comments
 (0)