Skip to content

Commit

Permalink
fix postgres query
Browse files Browse the repository at this point in the history
  • Loading branch information
matfish3 committed Nov 29, 2021
1 parent 3130452 commit ee1422f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Release Notes for Entry Meta

## 1.0.0-rc.1
## 1.0.0-rc.2 - 2021-11-29
### Fixed
- Fixed Postgres query

## 1.0.0-rc.1 - 2021-11-28
### Added
- Initial release
24 changes: 16 additions & 8 deletions src/services/EntryMetaQueryService.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function findEntriesByMetadata(array $params)

$first = true;

foreach ($params as $key=>$value) {
foreach ($params as $key => $value) {
$method = $first ? 'where' : 'andWhere';
$q = $q->{$method}($this->_getCondition($key, $value));
$first = false;
Expand Down Expand Up @@ -60,7 +60,7 @@ private function _transformValue($value)
return $value ? 'true' : 'false';
}

if (is_string($value) || $this->dbDriver===self::POSTGRES) {
if (is_string($value) || $this->dbDriver === self::POSTGRES) {
return "'{$value}'";
}

Expand All @@ -69,14 +69,22 @@ private function _transformValue($value)

private function _transformKey($key)
{
if ($this->dbDriver===self::POSTGRES) {
if ($this->dbDriver === self::POSTGRES) {
$keys = explode('.', $key);
$keys = array_map(function($key) {
$keys = array_map(function ($key) {
return "'{$key}'";
},$keys);
$nested = count($keys)>1;
$key = implode('->', $keys);
$key = ($nested ? '->':'->>') . $key;
}, $keys);
$nested = count($keys) > 1;

if ($nested) {
$lastSegment = array_pop($keys);
$key = implode('->', $keys);
$key .= '->>' . $lastSegment;
$key = '->' . $key;
} else {
$key = $keys[0];
$key = '->>' . $key;
}
}

return $key;
Expand Down

0 comments on commit ee1422f

Please sign in to comment.