Skip to content

Commit

Permalink
fix: fixed some inconsistencies on builder & grammar contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
mgcostaParedes committed Jun 1, 2021
1 parent 7bb416b commit 4bd79a7
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 3 additions & 2 deletions src/Spanner/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public function getBindings(): array
return Arr::collapse($this->bindings);
}

public function getRawBindings()
public function getRawBindings(): array
{
return $this->bindings;
}
Expand Down Expand Up @@ -506,7 +506,7 @@ public function orderByDesc($column): self
public function groupBy(...$groups): self
{
foreach ($groups as $group) {
$this->groups = array_merge((array) $this->groups, Arr::wrap($group));
$this->groups = array_merge((array)$this->groups, Arr::wrap($group));
}

return $this;
Expand Down Expand Up @@ -556,6 +556,7 @@ public function cloneWithout(array $properties)
}
});
}

public function cloneWithoutBindings(array $except)
{
return $this->tap($this->clone(), function ($clone) use ($except) {
Expand Down
1 change: 1 addition & 0 deletions src/Spanner/Builder/Grammar/Grammatical.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ interface Grammatical
public function compile(Builder $query): string;
public function compileUpdate(Builder $query, array $values): string;
public function compileDelete(Builder $query): string;
public function wrapTable($table);
}
21 changes: 10 additions & 11 deletions src/Spanner/Builder/Grammar/SpannerGrammar.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ public function compileDelete(Builder $query): string
);
}

public function wrapTable($table)
{
if (!$this->isExpression($table)) {
return $this->wrap($this->tablePrefix . $table, true);
}

return $table->getValue($table);
}

protected function compileComponents(Builder $query): array
{
$sql = [];
Expand Down Expand Up @@ -239,7 +248,7 @@ protected function concatenateWhereClauses($query, $sql): string
return $conjunction . ' ' . $this->removeLeadingBoolean(implode(' ', $sql));
}

private function whereBasic(Builder $query, array $where): string
protected function whereBasic(Builder $query, array $where): string
{
$value = $this->parameter($where);

Expand Down Expand Up @@ -316,22 +325,12 @@ protected function concatenate($segments): string
}));
}

public function wrapTable($table)
{
if (! $this->isExpression($table)) {
return $this->wrap($this->tablePrefix . $table, true);
}

return $table->getValue($table);
}

protected function wrap($value, $prefixAlias = false)
{
if ($this->isExpression($value)) {
return $value->getValue($value);
}


if (stripos($value, ' as ') !== false) {
return $this->wrapAliasedValue($value, $prefixAlias);
}
Expand Down
3 changes: 3 additions & 0 deletions src/Spanner/Builder/Interfaces/Operator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function join($table, $first, $operator = null, $second = null, $type = '

public function where($column, $operator = null, $value = null, $boolean = 'and'): Builder;
public function whereColumn($first, $operator = null, $second = null, $boolean = 'and'): Builder;
public function whereBetween($column, iterable $values, $boolean = 'and', $not = false): Builder;
public function whereNested(Closure $callback, $boolean = 'and'): Builder;
public function addNestedWhereQuery($query, $boolean = 'and'): Builder;
public function orWhere($column, $operator = null, $value = null): Builder;
Expand All @@ -46,4 +47,6 @@ public function crossJoin($table, $first = null, $operator = null, $second = nul

public function orderBy($column, $direction = 'asc'): Builder;
public function orderByDesc($column): Builder;

public function groupBy(array ...$groups): Builder;
}

0 comments on commit 4bd79a7

Please sign in to comment.