Skip to content

Commit

Permalink
Update join types and constants to match ANSI SQL specs
Browse files Browse the repository at this point in the history
Signed-off-by: pine3ree <[email protected]>
  • Loading branch information
pine3ree committed Oct 19, 2023
1 parent 140953c commit 8a2c0d4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 16 deletions.
48 changes: 45 additions & 3 deletions src/Command/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,20 @@ public function rightJoin(string $table, string $alias, $specification): self
return $this;
}

/**
* @see SqlSelect::fullJoin()
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function fullJoin(string $table, string $alias, $specification = null): self
{
$this->sqlStatement->fullJoin($table, $alias, $specification);
return $this;
}

/**
* @see SqlSelect::naturalJoin()
*
Expand All @@ -318,6 +332,20 @@ public function naturalJoin(string $table, string $alias, $specification = null)
return $this;
}

/**
* @see SqlSelect::naturalInnerJoin()
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function naturalInnerJoin(string $table, string $alias, $specification = null): self
{
$this->sqlStatement->naturalInnerJoin($table, $alias, $specification);
return $this;
}

/**
* @see SqlSelect::naturalLeftJoin()
*
Expand Down Expand Up @@ -346,6 +374,20 @@ public function naturalRightJoin(string $table, string $alias, $specification =
return $this;
}

/**
* @see SqlSelect::naturalFullJoin()
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function naturalFullJoin(string $table, string $alias, $specification = null): self
{
$this->sqlStatement->naturalFullJoin($table, $alias, $specification);
return $this;
}

/**
* @see SqlSelect::crossJoin()
*
Expand All @@ -361,16 +403,16 @@ public function crossJoin(string $table, string $alias, $specification = null):
}

/**
* @see SqlSelect::straightJoin()
* @see SqlSelect::unionJoin()
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function straightJoin(string $table, string $alias, $specification = null): self
public function unionJoin(string $table, string $alias, $specification = null): self
{
$this->sqlStatement->straightJoin($table, $alias, $specification);
$this->sqlStatement->unionJoin($table, $alias, $specification);
return $this;
}

Expand Down
14 changes: 10 additions & 4 deletions src/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,26 +91,32 @@ class Sql
* Join clause types
*/
public const JOIN_AUTO = '';
public const JOIN_INNER = 'INNER';
public const JOIN_CROSS = 'CROSS';
public const JOIN_UNION = 'UNION';
public const JOIN_INNER = 'INNER';
public const JOIN_LEFT = 'LEFT';
public const JOIN_RIGHT = 'RIGHT';
public const JOIN_STRAIGHT = 'STRAIGHT';
public const JOIN_FULL = 'FULL';
public const JOIN_NATURAL = 'NATURAL';
public const JOIN_NATURAL_INNER = 'NATURAL INNER';
public const JOIN_NATURAL_LEFT = 'NATURAL LEFT';
public const JOIN_NATURAL_RIGHT = 'NATURAL RIGHT';
public const JOIN_NATURAL_FULL = 'NATURAL_FULL';
public const USING = 'USING';

public const JOIN_TYPES = [
self::JOIN_AUTO => self::JOIN_AUTO,
self::JOIN_INNER => self::JOIN_INNER,
self::JOIN_CROSS => self::JOIN_CROSS,
self::JOIN_UNION => self::JOIN_UNION,
self::JOIN_INNER => self::JOIN_INNER,
self::JOIN_LEFT => self::JOIN_LEFT,
self::JOIN_RIGHT => self::JOIN_RIGHT,
self::JOIN_STRAIGHT => self::JOIN_STRAIGHT,
self::JOIN_FULL => self::JOIN_FULL,
self::JOIN_NATURAL => self::JOIN_NATURAL,
self::JOIN_NATURAL_INNER => self::JOIN_NATURAL_INNER,
self::JOIN_NATURAL_LEFT => self::JOIN_NATURAL_LEFT,
self::JOIN_NATURAL_RIGHT => self::JOIN_NATURAL_RIGHT,
self::JOIN_NATURAL_FULL => self::JOIN_NATURAL_FULL,
];

/*
Expand Down
59 changes: 52 additions & 7 deletions src/Sql/Statement/Select.php
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ public function innerJoin(string $table, string $alias, $specification = null):
}

/**
* Add a LEFT JOIN clause
* Add a LEFT [OUTER] JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
Expand All @@ -646,7 +646,7 @@ public function leftJoin(string $table, string $alias, $specification = null): s
}

/**
* Add a RIGHT JOIN clause
* Add a RIGHT [OUTER] JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
Expand All @@ -660,6 +660,21 @@ public function rightJoin(string $table, string $alias, $specification = null):
);
}

/**
* Add a FULL [OUTER] JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function fullJoin(string $table, string $alias, $specification = null): self
{
return $this->addJoin(
new Join(Sql::JOIN_FULL, $table, $alias, $specification)
);
}

/**
* Add a NATURAL JOIN clause
*
Expand All @@ -676,7 +691,22 @@ public function naturalJoin(string $table, string $alias, $specification = null)
}

/**
* Add a NATURAL LEFT JOIN clause
* Add a NATURAL INNER JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function naturalInnerJoin(string $table, string $alias, $specification = null): self
{
return $this->addJoin(
new Join(Sql::JOIN_NATURAL_INNER, $table, $alias, $specification)
);
}

/**
* Add a NATURAL LEFT [OUTER]JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
Expand All @@ -691,7 +721,7 @@ public function naturalLeftJoin(string $table, string $alias, $specification = n
}

/**
* Add a NATURAL RIGHT JOIN clause
* Add a NATURAL RIGHT [OUTER] JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
Expand All @@ -705,6 +735,21 @@ public function naturalRightJoin(string $table, string $alias, $specification =
);
}

/**
* Add a NATURAL FULL [OUTER] JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function naturalFullJoin(string $table, string $alias, $specification = null): self
{
return $this->addJoin(
new Join(Sql::JOIN_NATURAL_FULL, $table, $alias, $specification)
);
}

/**
* Add a CROSS JOIN clause
*
Expand All @@ -721,17 +766,17 @@ public function crossJoin(string $table, string $alias, $specification = null):
}

/**
* Add a STRAIGHT JOIN clause
* Add a UNION JOIN clause
*
* @param string $table The joined table name
* @param string $alias The joined table alias
* @param On|Predicate|Predicate\Set|array|string|Literal|Identifier|null $specification
* @return $this Fluent interface
*/
public function straightJoin(string $table, string $alias, $specification = null): self
public function unionJoin(string $table, string $alias, $specification = null): self
{
return $this->addJoin(
new Join(Sql::JOIN_STRAIGHT, $table, $alias, $specification)
new Join(Sql::JOIN_UNION, $table, $alias, $specification)
);
}

Expand Down
7 changes: 5 additions & 2 deletions test/Command/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,11 +385,14 @@ public function provideJoinOptions(): array
['crossJoin', Sql::JOIN_CROSS],
['innerJoin', Sql::JOIN_INNER],
['leftJoin', Sql::JOIN_LEFT],
['rightJoin', Sql::JOIN_RIGHT],
['fullJoin', Sql::JOIN_FULL],
['naturalJoin', Sql::JOIN_NATURAL],
['naturalInnerJoin', Sql::JOIN_NATURAL_INNER],
['naturalLeftJoin', Sql::JOIN_NATURAL_LEFT],
['naturalRightJoin', Sql::JOIN_NATURAL_RIGHT],
['rightJoin', Sql::JOIN_RIGHT],
['straightjoin', Sql::JOIN_STRAIGHT],
['naturalfullJoin', Sql::JOIN_NATURAL_FULL],
['unionjoin', Sql::JOIN_UNION],
];
}

Expand Down

0 comments on commit 8a2c0d4

Please sign in to comment.