Where trait

Framework\Database\Manipulation\Traits\Where

Trait Where.

Defined in libraries/database/src/Manipulation/Traits/Where.php

Methods #

orWhere()
Appends a "OR $column $operator ...$values" condition in the WHERE clause.
orWhereBetween()
Appends a "OR $column BETWEEN $min AND $max" condition in the WHERE clause.
orWhereEqual()
Appends a "OR $column = $value" condition in the WHERE clause.
orWhereGreaterThan()
Appends a "OR $column > $value" condition in the WHERE clause.
orWhereGreaterThanOrEqual()
Appends a "OR $column >= $value" condition in the WHERE clause.
orWhereIn()
Appends a "OR $column IN (...$values)" condition in the WHERE clause.
orWhereIsNotNull()
Appends a "OR $column IS NOT NULL" condition in the WHERE clause.
orWhereIsNull()
Appends a "OR $column IS NULL" condition in the WHERE clause.
orWhereLessThan()
Appends a "OR $column < $value" condition in the WHERE clause.
orWhereLessThanOrEqual()
Appends a "OR $column <= $value" condition in the WHERE clause.
orWhereLike()
Appends a "OR $column LIKE $value" condition in the WHERE clause.
orWhereMatch()
Appends a "OR MATCH (...$columns) AGAINST ($against IN NATURAL LANGUAGE MODE)" fulltext searching in the WHERE clause.
orWhereMatchInBooleanMode()
Appends a "OR MATCH (...$columns) AGAINST ($against IN BOOLEAN MODE)" fulltext searching in the WHERE clause.
orWhereMatchWithQueryExpansion()
Appends a "OR MATCH (...$columns) AGAINST ($against WITH QUERY EXPANSION)" fulltext searching in the WHERE clause.
orWhereNotBetween()
Appends a "OR $column NOT BETWEEN $min AND $max" condition in the WHERE clause.
orWhereNotEqual()
Appends a "OR $column != $value" condition in the WHERE clause.
orWhereNotIn()
Appends a "OR $column NOT IN (...$values)" condition in the WHERE clause.
orWhereNotLike()
Appends a "OR $column NOT LIKE $value" condition in the WHERE clause.
orWhereNullSafeEqual()
Appends a "OR $column <=> $value" condition in the WHERE clause.
where()
Appends an "AND $column $operator ...$values" condition in the WHERE clause.
whereBetween()
Appends an "AND $column BETWEEN $min AND $max" condition in the WHERE clause.
whereEqual()
Appends an "AND $column = $value" condition in the WHERE clause.
whereGreaterThan()
Appends an "AND $column > $value" condition in the WHERE clause.
whereGreaterThanOrEqual()
Appends an "AND $column >= $value" condition in the WHERE clause.
whereIn()
Appends an "AND $column IN (...$values)" condition in the WHERE clause.
whereIsNotNull()
Appends an "AND $column IS NOT NULL" condition in the WHERE clause.
whereIsNull()
Appends an "AND $column IS NULL" condition in the WHERE clause.
whereLessThan()
Appends an "AND $column < $value" condition in the WHERE clause.
whereLessThanOrEqual()
Appends an "AND $column <= $value" condition in the WHERE clause.
whereLike()
Appends an "AND $column LIKE $value" condition in the WHERE clause.
whereMatch()
Appends an "AND MATCH (...$columns) AGAINST ($against IN NATURAL LANGUAGE MODE)" fulltext searching in the WHERE clause.
whereMatchInBooleanMode()
Appends an "AND MATCH (...$columns) AGAINST ($against IN BOOLEAN MODE)" fulltext searching in the WHERE clause.
whereMatchWithQueryExpansion()
Appends an "AND MATCH (...$columns) AGAINST ($against WITH QUERY EXPANSION)" fulltext searching in the WHERE clause.
whereNotBetween()
Appends an "AND $column NOT BETWEEN $min AND $max" condition in the WHERE clause.
whereNotEqual()
Appends an "AND $column != $value" condition in the WHERE clause.
whereNotIn()
Appends an "AND $column NOT IN (...$values)" condition in the WHERE clause.
whereNotLike()
Appends an "AND $column NOT LIKE $value" condition.
whereNullSafeEqual()
Appends an "AND $column <=> $value" condition in the WHERE clause.
renderWhere()
Renders the full WHERE (or HAVING) clause.
addWhere()
Adds a WHERE (or HAVING) part.
prepareWhereValues()
Quote the input values or transform it in subqueries.
renderMatch()
Renders a MATCH AGAINST clause.
renderMatchColumns()
-
renderMatchExpression()
-
renderWhereOperator()
Renders and validates a comparison operator.
renderWherePart()
Renders a WHERE part. Like: `AND column IN('value1', 'value2')`.
renderWhereValues()
Renders the values used by a comparison operator.
renderWhereValuesPartBetween()
Renders values for `BETWEEN` or `NOT BETWEEN`.
renderWhereValuesPartComparator()
Renders the values of operators that receive exactly one value.
renderWhereValuesPartIn()
Implode values for `IN` or `NOT IN`.
renderWhereValuesPartIsNull()
Renders the lonely operators, `IS NULL` or `IS NOT NULL`.

orWhere()

public function orWhere(Closure|array|string $column, string $operator, Closure|array|string|int|float|null ...$values): static

Appends a "OR $column $operator ...$values" condition in the WHERE clause.

Parameters
  • Closure|array|string $column - Closure for a subquery, a string with the column name or an array with column names on WHERE MATCH clause
  • string $operator
  • Closure|array|string|int|float|null $values
Returns static

orWhereBetween()

public function orWhereBetween(Closure|string $column, Closure|string|int|float|null $min, Closure|string|int|float|null $max): static

Appends a "OR $column BETWEEN $min AND $max" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $min
  • Closure|string|int|float|null $max
Returns static

orWhereEqual()

public function orWhereEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column = $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereGreaterThan()

public function orWhereGreaterThan(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column > $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereGreaterThanOrEqual()

public function orWhereGreaterThanOrEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column >= $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereIn()

public function orWhereIn(Closure|string $column, Closure|string|int|float|null $value, Closure|string|int|float|null ...$values): static

Appends a "OR $column IN (...$values)" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
  • Closure|string|int|float|null $values
Returns static

orWhereIsNotNull()

public function orWhereIsNotNull(Closure|string $column): static

Appends a "OR $column IS NOT NULL" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
Returns static

orWhereIsNull()

public function orWhereIsNull(Closure|string $column): static

Appends a "OR $column IS NULL" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
Returns static

orWhereLessThan()

public function orWhereLessThan(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column < $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereLessThanOrEqual()

public function orWhereLessThanOrEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column <= $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereLike()

public function orWhereLike(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column LIKE $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereMatch()

public function orWhereMatch(Closure|array|string $columns, Closure|array|string $against): static

Appends a "OR MATCH (...$columns) AGAINST ($against IN NATURAL LANGUAGE MODE)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

orWhereMatchInBooleanMode()

public function orWhereMatchInBooleanMode(Closure|array|string $columns, Closure|array|string $against): static

Appends a "OR MATCH (...$columns) AGAINST ($against IN BOOLEAN MODE)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

orWhereMatchWithQueryExpansion()

public function orWhereMatchWithQueryExpansion(Closure|array|string $columns, Closure|array|string $against): static

Appends a "OR MATCH (...$columns) AGAINST ($against WITH QUERY EXPANSION)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

orWhereNotBetween()

public function orWhereNotBetween(Closure|string $column, Closure|string|int|float|null $min, Closure|string|int|float|null $max): static

Appends a "OR $column NOT BETWEEN $min AND $max" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $min
  • Closure|string|int|float|null $max
Returns static

orWhereNotEqual()

public function orWhereNotEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column != $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereNotIn()

public function orWhereNotIn(Closure|string $column, Closure|string|int|float|null $value, Closure|string|int|float|null ...$values): static

Appends a "OR $column NOT IN (...$values)" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
  • Closure|string|int|float|null $values
Returns static

orWhereNotLike()

public function orWhereNotLike(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column NOT LIKE $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

orWhereNullSafeEqual()

public function orWhereNullSafeEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends a "OR $column <=> $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

where()

public function where(Closure|array|string $column, string $operator, Closure|array|string|int|float|null ...$values): static

Appends an "AND $column $operator ...$values" condition in the WHERE clause.

Parameters
  • Closure|array|string $column - Closure for a subquery, a string with the column name or an array with column names on WHERE MATCH clause
  • string $operator
  • Closure|array|string|int|float|null $values
Returns static

whereBetween()

public function whereBetween(Closure|string $column, Closure|string|int|float|null $min, Closure|string|int|float|null $max): static

Appends an "AND $column BETWEEN $min AND $max" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $min
  • Closure|string|int|float|null $max
Returns static

whereEqual()

public function whereEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column = $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereGreaterThan()

public function whereGreaterThan(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column > $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereGreaterThanOrEqual()

public function whereGreaterThanOrEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column >= $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereIn()

public function whereIn(Closure|string $column, Closure|string|int|float|null $value, Closure|string|int|float|null ...$values): static

Appends an "AND $column IN (...$values)" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
  • Closure|string|int|float|null $values
Returns static

whereIsNotNull()

public function whereIsNotNull(Closure|string $column): static

Appends an "AND $column IS NOT NULL" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
Returns static

whereIsNull()

public function whereIsNull(Closure|string $column): static

Appends an "AND $column IS NULL" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
Returns static

whereLessThan()

public function whereLessThan(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column < $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereLessThanOrEqual()

public function whereLessThanOrEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column <= $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereLike()

public function whereLike(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column LIKE $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereMatch()

public function whereMatch(Closure|array|string $columns, Closure|array|string $against): static

Appends an "AND MATCH (...$columns) AGAINST ($against IN NATURAL LANGUAGE MODE)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

whereMatchInBooleanMode()

public function whereMatchInBooleanMode(Closure|array|string $columns, Closure|array|string $against): static

Appends an "AND MATCH (...$columns) AGAINST ($against IN BOOLEAN MODE)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

whereMatchWithQueryExpansion()

public function whereMatchWithQueryExpansion(Closure|array|string $columns, Closure|array|string $against): static

Appends an "AND MATCH (...$columns) AGAINST ($against WITH QUERY EXPANSION)" fulltext searching in the WHERE clause.

Parameters
  • Closure|array|string $columns - Columns to MATCH
  • Closure|array|string $against - AGAINST expression
Returns static

whereNotBetween()

public function whereNotBetween(Closure|string $column, Closure|string|int|float|null $min, Closure|string|int|float|null $max): static

Appends an "AND $column NOT BETWEEN $min AND $max" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $min
  • Closure|string|int|float|null $max
Returns static

whereNotEqual()

public function whereNotEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column != $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereNotIn()

public function whereNotIn(Closure|string $column, Closure|string|int|float|null $value, Closure|string|int|float|null ...$values): static

Appends an "AND $column NOT IN (...$values)" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
  • Closure|string|int|float|null $values
Returns static

whereNotLike()

public function whereNotLike(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column NOT LIKE $value" condition.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

whereNullSafeEqual()

public function whereNullSafeEqual(Closure|string $column, Closure|string|int|float|null $value): static

Appends an "AND $column <=> $value" condition in the WHERE clause.

Parameters
  • Closure|string $column - Closure for a subquery or a string with the column name
  • Closure|string|int|float|null $value
Returns static

renderWhere()

protected function renderWhere(string $clause = 'where'): ?string

Renders the full WHERE (or HAVING) clause.

Parameters
  • string $clause - `where` or `having`
Returns ?string - The full clause or null if has not a clause

addWhere()

private function addWhere(string $glue, Closure|array|string $column, string $operator, array $values, string $clause = 'where'): static

Adds a WHERE (or HAVING) part.

Parameters
  • string $glue - `AND` or `OR`
  • Closure|array|string $column
  • string $operator - `=`, `<=>`, `!=`, `<>`, `>`, `>=`, `<`, `<=`, `LIKE`, `NOT LIKE`, `IN`, `NOT IN`, `BETWEEN`, `NOT BETWEEN`, `IS NULL`, `IS NOT NULL` or `MATCH`
  • array $values - Values used by the operator
  • string $clause - `where` or `having`
Returns static

prepareWhereValues()

private function prepareWhereValues(array $values): array

Quote the input values or transform it in subqueries.

Parameters
  • array $values
Returns array - Each input value quoted or transformed in subquery

renderMatch()

private function renderMatch(Closure|array|string $columns, Closure|array|string $expression, string $modifier = '')

Renders a MATCH AGAINST clause.

Parameters
  • Closure|array|string $columns
  • Closure|array|string $expression
  • string $modifier
Returns string

renderMatchColumns()

private function renderMatchColumns(Closure|array|string $columns): string
Parameters
  • Closure|array|string $columns
Returns string

renderMatchExpression()

private function renderMatchExpression(Closure|array|string $expression): string|int|float
Parameters
  • Closure|array|string $expression
Returns string|int|float

renderWhereOperator()

private function renderWhereOperator(string $operator): string

Renders and validates a comparison operator.

Parameters
  • string $operator - `=`, `<=>`, `!=`, `<>`, `>`, `>=`, `<`, `<=`, `LIKE`, `NOT LIKE`, `IN`, `NOT IN`, `BETWEEN`, `NOT BETWEEN`, `IS NULL` or `IS NOT NULL`
Returns string - The operator
throws
InvalidArgumentException for invalid comparison operator

renderWherePart()

private function renderWherePart(array $part, bool $first = false): string

Renders a WHERE part. Like: `AND column IN('value1', 'value2')`.

Parameters
  • array $part - Keys: `glue`, `operator`, `column` and `values`
  • bool $first - Is the first part? Prepends the operator (`AND` or `OR`)
Returns string

renderWhereValues()

private function renderWhereValues(string $operator, array $values): ?string

Renders the values used by a comparison operator.

Parameters
  • string $operator - `=`, `<=>`, `!=`, `<>`, `>`, `>=`, `<`, `<=`, `LIKE`, `NOT LIKE`, `IN`, `NOT IN`, `BETWEEN`, `NOT BETWEEN`, `IS NULL` or `IS NOT NULL`
  • array $values
Returns ?string - The values used by the operator
throws
InvalidArgumentException for invalid comparison operator

renderWhereValuesPartBetween()

private function renderWhereValuesPartBetween(string $operator, array $values): string

Renders values for `BETWEEN` or `NOT BETWEEN`.

Parameters
  • string $operator - `BETWEEN` or `NOT BETWEEN`
  • array $values - Two values, indexes 0 and 1
Returns string
throws
InvalidArgumentException if $values not receive exactly two values

renderWhereValuesPartComparator()

private function renderWhereValuesPartComparator(string $operator, array $values): string

Renders the values of operators that receive exactly one value.

Parameters
  • string $operator - `=`, `<=>`, `!=`, `<>`, `>`, `>=`, `<`, `<=`, `LIKE` or `NOT LIKE`
  • array $values - Must receive exactly 1 value, index 0
Returns string
throws
InvalidArgumentException if $values has more than one value

renderWhereValuesPartIn()

private function renderWhereValuesPartIn(string $operator, array $values): string

Implode values for `IN` or `NOT IN`.

Parameters
  • string $operator - `IN` or `NOT IN`
  • array $values - Must receive at least 1 value
Returns string
throws
InvalidArgumentException if $values does not receive any value

renderWhereValuesPartIsNull()

private function renderWhereValuesPartIsNull(string $operator, array $values)

Renders the lonely operators, `IS NULL` or `IS NOT NULL`.

Parameters
  • string $operator - `IS NULL` or `IS NOT NULL`
  • array $values - Must be an empty array
Returns null
throws
InvalidArgumentException if $values is not empty