Skip to content

Commit d406957

Browse files
thebatclaudioClaudio La Barbera
and
Claudio La Barbera
authored
Allow KeyConditionExpression when model has composite key and partition key only is passed in where (#254)
* Allow KeyConditionExpression when model has composite key and partition key only is passed in where * fix: check if all conditions columns are present in model key names * fix: array_search can return 0 so we can't use only ! but we have to check if the result is === false * aws_iam_role debug taken from env * excluded .idea folder from git * changed composer info * fix check on wrong place * use APP_DEBUG if DYNAMO_DEBUG is not set * fixed check on condition * only DYNAMODB_DEBUG --------- Co-authored-by: Claudio La Barbera <[email protected]>
1 parent 9638116 commit d406957

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ dynamodb_local_test.db
44
/nbproject
55
*.log
66
.php_cs.cache
7+
.idea
78

89
.phpunit.result.cache

config/dynamodb.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
],
4040
'aws_iam_role' => [
4141
'region' => env('DYNAMODB_REGION'),
42-
'debug' => true,
42+
'debug' => env('DYNAMODB_DEBUG'),
4343
],
4444
'local' => [
4545
'credentials' => [

src/ConditionAnalyzer/Analyzer.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,18 @@ public function isExactSearch()
7171
return false;
7272
}
7373

74+
if (count($this->conditions) !== count($this->model->getKeyNames())) {
75+
return false;
76+
}
77+
7478
foreach ($this->conditions as $condition) {
7579
if (Arr::get($condition, 'type') !== ComparisonOperator::EQ) {
7680
return false;
7781
}
82+
83+
if (array_search(Arr::get($condition, 'column'), $this->model->getKeyNames()) === false) {
84+
return false;
85+
}
7886
}
7987

8088
return true;
@@ -202,8 +210,8 @@ private function hasValidQueryOperator($hash, $range = null)
202210
$hashConditionType = $this->getCondition($hash)['type'] ?? null;
203211
$validQueryOp = ComparisonOperator::isValidQueryDynamoDbOperator($hashConditionType);
204212

205-
if ($validQueryOp && $range) {
206-
$rangeConditionType = $this->getCondition($range)['type'] ?? null;
213+
if ($validQueryOp && $range && $this->getCondition($range) !== null) {
214+
$rangeConditionType = $this->getCondition($range)['type'];
207215
$validQueryOp = ComparisonOperator::isValidQueryDynamoDbOperator(
208216
$rangeConditionType,
209217
true

0 commit comments

Comments
 (0)