Skip to content

Commit

Permalink
Merge branch 'v1'
Browse files Browse the repository at this point in the history
  • Loading branch information
baopham committed Oct 19, 2017
2 parents 1b83ef0 + cd4a4a9 commit 98d7a92
Showing 1 changed file with 6 additions and 22 deletions.
28 changes: 6 additions & 22 deletions src/DynamoDbQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,13 @@ public function removeAttribute(...$attributes)
$this->resetExpressions();

try {
$this->client->updateItem(array_filter([
$query = [
'TableName' => $this->model->getTable(),
'Key' => $key,
'UpdateExpression' => $this->updateExpression->remove($attributes),
'ExpressionAttributeNames' => $this->expressionAttributeNames->all(),
]));
];
$this->client->updateItem($this->cleanUpQuery($query));

return true;
} catch (Exception $e) {
Expand Down Expand Up @@ -517,8 +518,7 @@ protected function getAll($columns = [], $limit = -1, $use_iterator = true)
$queryInfo = $this->buildExpressionQuery();
$op = $queryInfo['op'];
$query = array_merge($query, $queryInfo['query']);

$this->cleanUpQuery($query);
$query = $this->cleanUpQuery($query);

if ($use_iterator) {
$iterator = $this->client->getIterator($op, $query);
Expand Down Expand Up @@ -763,25 +763,9 @@ protected function isMultipleIds($id)
return $hasCompositeKey ? is_array(array_first($id)) : is_array($id);
}

protected function cleanUpQuery(&$query)
private function cleanUpQuery($query)
{
if (empty($query['KeyConditionExpression']) && empty($query['FilterExpression'])) {
unset($query['ExpressionAttributeNames']);
unset($query['ExpressionAttributeValues']);
}

$nonEmptyOnly = [
'ExpressionAttributeNames',
'ExpressionAttributeValues',
'KeyConditionExpression',
'FilterExpression',
];

foreach ($nonEmptyOnly as $attr) {
if (empty($query[$attr])) {
unset($query[$attr]);
}
}
return array_filter($query);
}

/**
Expand Down

0 comments on commit 98d7a92

Please sign in to comment.