Aplus Framework Database Library

Join

Trait Join.

Tags
see
https://mariadb.com/kb/en/joins/
todo

STRAIGHT_JOIN - https://mariadb.com/kb/en/index-hints-how-to-force-query-plans/

Table of Contents

crossJoin()  : static
Adds a JOIN clause with "CROSS JOIN $table".
crossJoinOn()  : static
Adds a JOIN clause with "CROSS JOIN $table ON $conditional".
crossJoinUsing()  : static
Adds a JOIN clause with "CROSS JOIN $table USING ...$columns".
from()  : static
Sets the FROM clause.
innerJoinOn()  : static
Adds a JOIN clause with "INNER JOIN $table ON $conditional".
innerJoinUsing()  : static
Adds a JOIN clause with "INNER JOIN $table USING ...$columns".
join()  : static
Adds a JOIN clause with "$type JOIN $table $clause $conditional".
joinOn()  : static
Adds a JOIN clause with "JOIN $table ON $conditional".
joinUsing()  : static
Adds a JOIN clause with "JOIN $table USING ...$columns".
leftJoinOn()  : static
Adds a JOIN clause with "LEFT JOIN $table ON $conditional".
leftJoinUsing()  : static
Adds a JOIN clause with "LEFT JOIN $table USING ...$columns".
leftOuterJoinOn()  : static
Adds a JOIN clause with "LEFT OUTER JOIN $table ON $conditional".
leftOuterJoinUsing()  : static
Adds a JOIN clause with "LEFT OUTER JOIN $table USING ...$columns".
naturalJoin()  : static
Adds a JOIN clause with "NATURAL JOIN $table".
naturalLeftJoin()  : static
Adds a JOIN clause with "NATURAL LEFT JOIN $table".
naturalLeftOuterJoin()  : static
Adds a JOIN clause with "NATURAL LEFT OUTER JOIN $table".
naturalRightJoin()  : static
Adds a JOIN clause with "NATURAL RIGHT JOIN $table".
naturalRightOuterJoin()  : static
Adds a JOIN clause with "NATURAL RIGHT OUTER JOIN $table".
rightJoinOn()  : static
Adds a JOIN clause with "RIGHT JOIN $table ON $conditional".
rightJoinUsing()  : static
Adds a JOIN clause with "RIGHT JOIN $table USING ...$columns".
rightOuterJoinOn()  : static
Adds a JOIN clause with "RIGHT OUTER JOIN $table ON $conditional".
rightOuterJoinUsing()  : static
Adds a JOIN clause with "RIGHT OUTER JOIN $table USING ...$columns".
hasFrom()  : bool
Tells if the FROM clause was set.
renderFrom()  : string|null
Renders the FROM clause.
renderJoin()  : string|null
Renders the JOIN clause.
checkNaturalJoinType()  : bool
Check if a JOIN type belongs to the NATURAL group.
renderJoinConditional()  : string
Renders the JOIN conditional part.
renderJoinConditionClause()  : string|null
Validates and renders the JOIN condition clause.
renderJoinConditionExpression()  : string|null
Renders the JOIN condition expression.
renderJoinType()  : string
Validates and renders the JOIN type.
setJoin()  : static
Sets the JOIN clause.

Methods

crossJoin()

Adds a JOIN clause with "CROSS JOIN $table".

public crossJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

crossJoinOn()

Adds a JOIN clause with "CROSS JOIN $table ON $conditional".

public crossJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

crossJoinUsing()

Adds a JOIN clause with "CROSS JOIN $table USING ...$columns".

public crossJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

from()

Sets the FROM clause.

public from(array<string, \Closure|string>|Closure|string $reference, array<string, \Closure|string>|Closure|string ...$references) : static
Parameters
$reference : array<string, \Closure|string>|Closure|string

Table reference

$references : array<string, \Closure|string>|Closure|string

Table references

Tags
see
https://mariadb.com/kb/en/join-syntax/
Return values
static

innerJoinOn()

Adds a JOIN clause with "INNER JOIN $table ON $conditional".

public innerJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

innerJoinUsing()

Adds a JOIN clause with "INNER JOIN $table USING ...$columns".

public innerJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

join()

Adds a JOIN clause with "$type JOIN $table $clause $conditional".

public join(array<string, \Closure|string>|Closure|string $table[, string $type = '' ][, string|null $clause = null ][, array<int, \Closure|string>|Closure|null $conditional = null ]) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$type : string = ''

JOIN type. One of: CROSS, INNER, LEFT, LEFT OUTER, RIGHT, RIGHT OUTER, NATURAL, NATURAL LEFT, NATURAL LEFT OUTER, NATURAL RIGHT, NATURAL RIGHT OUTER or empty (same as INNER)

$clause : string|null = null

Condition clause. Null if it has a NATURAL type, otherwise ON or USING

$conditional : array<int, \Closure|string>|Closure|null = null

A conditional expression as Closure or the columns list as array

Return values
static

joinOn()

Adds a JOIN clause with "JOIN $table ON $conditional".

public joinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

joinUsing()

Adds a JOIN clause with "JOIN $table USING ...$columns".

public joinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

leftJoinOn()

Adds a JOIN clause with "LEFT JOIN $table ON $conditional".

public leftJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

leftJoinUsing()

Adds a JOIN clause with "LEFT JOIN $table USING ...$columns".

public leftJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

leftOuterJoinOn()

Adds a JOIN clause with "LEFT OUTER JOIN $table ON $conditional".

public leftOuterJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

leftOuterJoinUsing()

Adds a JOIN clause with "LEFT OUTER JOIN $table USING ...$columns".

public leftOuterJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

naturalJoin()

Adds a JOIN clause with "NATURAL JOIN $table".

public naturalJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

naturalLeftJoin()

Adds a JOIN clause with "NATURAL LEFT JOIN $table".

public naturalLeftJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

naturalLeftOuterJoin()

Adds a JOIN clause with "NATURAL LEFT OUTER JOIN $table".

public naturalLeftOuterJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

naturalRightJoin()

Adds a JOIN clause with "NATURAL RIGHT JOIN $table".

public naturalRightJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

naturalRightOuterJoin()

Adds a JOIN clause with "NATURAL RIGHT OUTER JOIN $table".

public naturalRightOuterJoin(array<string, \Closure|string>|Closure|string $table) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

Return values
static

rightJoinOn()

Adds a JOIN clause with "RIGHT JOIN $table ON $conditional".

public rightJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

rightJoinUsing()

Adds a JOIN clause with "RIGHT JOIN $table USING ...$columns".

public rightJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

rightOuterJoinOn()

Adds a JOIN clause with "RIGHT OUTER JOIN $table ON $conditional".

public rightOuterJoinOn(array<string, \Closure|string>|Closure|string $table, Closure $conditional) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$conditional : Closure

Conditional expression

Return values
static

rightOuterJoinUsing()

Adds a JOIN clause with "RIGHT OUTER JOIN $table USING ...$columns".

public rightOuterJoinUsing(array<string, \Closure|string>|Closure|string $table, Closure|string ...$columns) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

Table factor

$columns : Closure|string

Columns list

Return values
static

hasFrom()

Tells if the FROM clause was set.

protected hasFrom([string|null $clause = null ]) : bool
Parameters
$clause : string|null = null

A clause where FROM is required

Tags
throws
LogicException

if FROM is not set, but is required for some other clause

Return values
bool

True if it has FROM, otherwise false

renderFrom()

Renders the FROM clause.

protected renderFrom() : string|null
Return values
string|null

The FROM clause or null if it was not set

renderJoin()

Renders the JOIN clause.

protected renderJoin() : string|null
Return values
string|null

The JOIN clause or null if it was not set

checkNaturalJoinType()

Check if a JOIN type belongs to the NATURAL group.

private checkNaturalJoinType(string $type, string|null $clause, array<string|int, \Closure|string>|Closure|null $expression) : bool
Parameters
$type : string

NATURAL, NATURAL LEFT, NATURAL LEFT OUTER, NATURAL RIGHT, NATURAL RIGHT OUTER or any other non-natural

$clause : string|null

Must be null if type is natural

$expression : array<string|int, \Closure|string>|Closure|null

Must be null if type is natural

Tags
throws
InvalidArgumentException

if $type is natural and has clause or expression

Return values
bool

True if the type is natural, otherwise false

renderJoinConditional()

Renders the JOIN conditional part.

private renderJoinConditional(string $type, array<string, \Closure|string>|Closure|string $table, string|null $clause, array<string|int, \Closure|string>|Closure|null $expression) : string
Parameters
$type : string

``, CROSS,INNER, LEFT, LEFT OUTER, RIGHT, RIGHT OUTER, NATURAL, NATURAL LEFT, NATURAL LEFT OUTER, NATURAL RIGHT or NATURAL RIGHT OUTER

$table : array<string, \Closure|string>|Closure|string

The table name

$clause : string|null

ON, USING or null for none

$expression : array<string|int, \Closure|string>|Closure|null

Column(s) or subquery(ies)

Return values
string

The JOIN conditional part

renderJoinConditionClause()

Validates and renders the JOIN condition clause.

private renderJoinConditionClause(string|null $clause) : string|null
Parameters
$clause : string|null

ON, USING or null for none

Tags
throws
InvalidArgumentException

for invalid condition clause

Return values
string|null

The condition clause or none

renderJoinConditionExpression()

Renders the JOIN condition expression.

private renderJoinConditionExpression(string|null $clause, array<string|int, \Closure|string>|Closure|null $expression) : string|null
Parameters
$clause : string|null

ONor null

$expression : array<string|int, \Closure|string>|Closure|null

Column(s) or subquery(ies)

Return values
string|null

The condition or null if $clause is null

renderJoinType()

Validates and renders the JOIN type.

private renderJoinType(string $type) : string
Parameters
$type : string

``, CROSS,INNER, LEFT, LEFT OUTER, RIGHT, RIGHT OUTER, NATURAL, NATURAL LEFT, NATURAL LEFT OUTER, NATURAL RIGHT or NATURAL RIGHT OUTER

Tags
throws
InvalidArgumentException

for invalid type

Return values
string

The input ype

setJoin()

Sets the JOIN clause.

private setJoin(array<string, \Closure|string>|Closure|string $table, string $type[, string|null $clause = null ][, array<string|int, \Closure|string>|Closure|null $expression = null ]) : static
Parameters
$table : array<string, \Closure|string>|Closure|string

The table factor

$type : string

``, CROSS, INNER, LEFT, LEFT OUTER, RIGHT, RIGHT OUTER, NATURAL, NATURAL LEFT, NATURAL LEFT OUTER, NATURAL RIGHT or NATURAL RIGHT OUTER

$clause : string|null = null

ON, USING or null for none

$expression : array<string|int, \Closure|string>|Closure|null = null

Column(s) or subquery(ies)

Return values
static

Search results