Skip to content

Commit

Permalink
Merge pull request #79 from baopham/expression
Browse files Browse the repository at this point in the history
Upgrade legacy attributes
  • Loading branch information
baopham authored Aug 13, 2017
2 parents 6a22e38 + d02991d commit 9a804dd
Show file tree
Hide file tree
Showing 13 changed files with 725 additions and 129 deletions.
31 changes: 18 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,26 @@ $model->delete();
// Using getIterator(). If 'key' is the primary key or a global/local index and the condition is EQ, will use 'Query', otherwise 'Scan'.
$model->where('key', 'key value')->get();
// See BaoPham\DynamoDb\ComparisonOperator
$model->where(['key' => 'key value']);
// Chainable for 'AND'. 'OR' is not supported.
// Chainable for 'AND'. 'OR' is not tested.
$model->where('foo', 'bar')
->where('foo2', '!=' 'bar2')
->get();
$model->where('count', 'between', [0, 100])->get();
$model->where('count', '>', 0)->get();
$model->where('description', 'begins_with', 'foo')->get();
$model->where('description', 'contains', 'foo')->get();
$model->where('description', 'not_contains', 'foo')->get();
```
##### whereNull() and whereNotNull()
> NULL and NOT_NULL only check for the attribute presence not its value being null
> See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
```php
$model->whereNull('name');
$model->whereNotNull('name');
```
#### all() and first()
Expand Down Expand Up @@ -161,16 +175,6 @@ $model->findOrFail('foo');
$model->findOrFail(['id' => 'foo', 'id2' => 'bar']);
```
#### whereNull() and whereNotNull()
> NULL and NOT_NULL only check for the attribute presence not its value being null
> See: http://docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Condition.html
```php
$model->whereNull('name');
$model->whereNotNull('name');
```
Indexes
-----------
If your table has indexes, make sure to declare them in your model class like so
Expand Down Expand Up @@ -259,7 +263,8 @@ Laravel ^5.1
TODO
----
- [ ] Upgrade a few legacy attributes: `AttributesToGet`, `ScanFilter`, ...
- [ ] Nested conditions
- [ ] Verify OR conditions
FAQ
---
Expand Down
4 changes: 2 additions & 2 deletions src/ComparisonOperator.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ public static function isValidQueryDynamoDbOperator($dynamoDbOperator, $isRangeK
return in_array($dynamoDbOperator, static::getQuerySupportedOperators($isRangeKey));
}

public static function is($op, $opToCompare)
public static function is($op, $dynamoDbOperator)
{
$mapping = static::getOperatorMapping();
return $mapping[strtolower($op)] === $opToCompare;
return $mapping[strtolower($op)] === $dynamoDbOperator;
}
}
27 changes: 18 additions & 9 deletions src/DynamoDbModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ abstract class DynamoDbModel extends Model

/**
* Indexes.
* [
* 'global_index_key' => 'global_index_name',
* 'local_index_key' => 'local_index_name',
* ].
* [
* 'simple_index_name' => [
* 'hash' => 'index_key'
* ],
* 'composite_index_name' => [
* 'hash' => 'index_hash_key',
* 'range' => 'index_range_key'
* ],
* ]
*
* @var array
*/
Expand Down Expand Up @@ -198,11 +203,7 @@ public static function all($columns = [])
*/
public function newQuery()
{
$builder = new DynamoDbQueryBuilder();

$builder->setModel($this);

$builder->setClient($this->client);
$builder = new DynamoDbQueryBuilder($this);

return $builder;
}
Expand Down Expand Up @@ -294,6 +295,14 @@ public function setDynamoDbIndexKeys($dynamoDbIndexKeys)
$this->dynamoDbIndexKeys = $dynamoDbIndexKeys;
}

/**
* @return \Aws\DynamoDb\Marshaler
*/
public function getMarshaler()
{
return $this->marshaler;
}

/**
* Remove non-serializable properties when serializing.
*
Expand Down
Loading

0 comments on commit 9a804dd

Please sign in to comment.