Skip to content

Commit

Permalink
Fluent: add Lateral joins [WIP + TESTS]
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest79 committed Sep 18, 2023
1 parent a757fff commit dda8b1c
Show file tree
Hide file tree
Showing 3 changed files with 282 additions and 0 deletions.
107 changes: 107 additions & 0 deletions src/Fluent/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,113 @@ public function crossJoin($join, ?string $alias = NULL): Query
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function joinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->joinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function innerJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->innerJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function leftJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->leftJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function leftOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->leftOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function rightJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->rightJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function rightOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->rightOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function fullJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->fullJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function fullOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query
{
return $this->createQuery()->fullOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|Query|Db\Sql $join table or query
* @return QueryExecute
* @throws Exceptions\QueryException
*/
public function crossJoinLateral($join, ?string $alias = NULL): Query
{
return $this->createQuery()->crossJoinLateral($join, $alias);
}


/**
* @param string|Complex|Db\Sql $condition
* @param mixed ...$params
Expand Down
113 changes: 113 additions & 0 deletions src/Fluent/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Query implements Sql
private const JOIN_FULL_OUTER = 'FULL OUTER JOIN';
public const JOIN_CROSS = 'CROSS JOIN';

private const JOIN_INNER_LATERAL = 'INNER JOIN LATERAL';
private const JOIN_LEFT_OUTER_LATERAL = 'LEFT OUTER JOIN LATERAL';
private const JOIN_RIGHT_OUTER_LATERAL = 'RIGHT OUTER JOIN LATERAL';
private const JOIN_FULL_OUTER_LATERAL = 'FULL OUTER JOIN LATERAL';
public const JOIN_CROSS_LATERAL = 'CROSS JOIN LATERAL';

private const COMBINE_UNION = 'UNION';
private const COMBINE_UNION_ALL = 'UNION ALL';
private const COMBINE_INTERSECT = 'INTERSECT';
Expand Down Expand Up @@ -263,6 +269,113 @@ public function crossJoin($join, ?string $alias = NULL): self
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function joinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->innerJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function innerJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->addTable(self::JOIN_INNER_LATERAL, $join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function leftJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->leftOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function leftOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->addTable(self::JOIN_LEFT_OUTER_LATERAL, $join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function rightJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->rightOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function rightOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->addTable(self::JOIN_RIGHT_OUTER_LATERAL, $join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function fullJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->fullOuterJoinLateral($join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
* @return static
* @throws Exceptions\QueryException
*/
public function fullOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): self
{
return $this->addTable(self::JOIN_FULL_OUTER_LATERAL, $join, $alias, $onCondition);
}


/**
* @param string|self|Db\Sql $join table or query
* @return static
* @throws Exceptions\QueryException
*/
public function crossJoinLateral($join, ?string $alias = NULL): self
{
return $this->addTable(self::JOIN_CROSS_LATERAL, $join, $alias);
}


/**
* @param string|self|Db\Sql $name
* @param string|Complex|Db\Sql|NULL $onCondition
Expand Down
62 changes: 62 additions & 0 deletions src/Fluent/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,68 @@ function fullOuterJoin($join, ?string $alias = NULL, $onCondition = NULL): Query
function crossJoin($join, ?string $alias = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function joinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function innerJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function leftJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function leftOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function rightJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function rightOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function fullJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
* @param string|Complex|Db\Sql|NULL $onCondition
*/
function fullOuterJoinLateral($join, ?string $alias = NULL, $onCondition = NULL): Query;


/**
* @param string|Query|Db\Sql $join table or query
*/
function crossJoinLateral($join, ?string $alias = NULL): Query;


/**
* @param string|Complex|Db\Sql $condition
* @param mixed ...$params
Expand Down

0 comments on commit dda8b1c

Please sign in to comment.