Skip to content
Merged

WIP #27

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 42 additions & 25 deletions src/CachedBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,35 +74,27 @@ protected function getQueryColumns(array $columns) : string

protected function getWhereClauses(array $wheres = []) : string
{
$wheres = collect($wheres);

if ($wheres->isEmpty()) {
$wheres = collect($this->query->wheres);
}

return $wheres->reduce(function ($carry, $where) {
if (in_array($where['type'], ['Exists', 'Nested', 'NotExists'])) {
return '_' . strtolower($where['type']) . $this->getWhereClauses($where['query']->wheres);
}
return $this->getWheres($wheres)
->reduce(function ($carry, $where) {
if (in_array($where['type'], ['Exists', 'Nested', 'NotExists'])) {
return '_' . strtolower($where['type']) . $this->getWhereClauses($where['query']->wheres);
}

if ($where['type'] === 'Column') {
return "_{$where['boolean']}_{$where['first']}_{$where['operator']}_{$where['second']}";
}
if ($where['type'] === 'Column') {
return "_{$where['boolean']}_{$where['first']}_{$where['operator']}_{$where['second']}";
}

if ($where['type'] === 'raw') {
return "_{$where['boolean']}_" . str_slug($where['sql']);
}
if ($where['type'] === 'raw') {
return "_{$where['boolean']}_" . str_slug($where['sql']);
}

$value = array_get($where, 'value');
$value .= in_array($where['type'], ['In', 'Null', 'NotNull'])
? strtolower($where['type'])
: '';
$value .= is_array(array_get($where, 'values'))
? '_' . implode('_', $where['values'])
: '';
$value = array_get($where, 'value');
$value .= $this->getTypeClause($where);
$value .= $this->getValuesClause($where);

return "{$carry}-{$where['column']}_{$value}";
}) ?: '';
return "{$carry}-{$where['column']}_{$value}";
})
. '';
}

protected function getWithModels() : string
Expand Down Expand Up @@ -246,4 +238,29 @@ public function sum($column)
return parent::sum($column);
});
}

protected function getTypeClause($where)
{
return in_array($where['type'], ['In', 'Null', 'NotNull'])
? strtolower($where['type'])
: '';
}

protected function getValuesClause($where)
{
return is_array(array_get($where, 'values'))
? '_' . implode('_', $where['values'])
: '';
}

protected function getWheres(array $wheres) : Collection
{
$wheres = collect($wheres);

if ($wheres->isEmpty()) {
$wheres = collect($this->query->wheres);
}

return $wheres;
}
}