ulmus/src/Query/Join.php
Dave Mc Nicoll 139504f8dd - Added the HAVING and TRUNCATE keyword
- Fixed GroupBy which was not implemented yet
- Added a new SQL raw() function
- From statement now accepts subqueries
2020-10-06 11:00:12 -04:00

64 lines
1.6 KiB
PHP

<?php
namespace Ulmus\Query;
use Ulmus\QueryBuilder;
use Ulmus\Repository\ConditionTrait;
class Join extends Fragment
{
use ConditionTrait;
const SQL_OUTER = "OUTER";
const SQL_TOKEN = "JOIN";
const TYPE_LEFT = "LEFT";
const TYPE_RIGHT = "RIGHT";
const TYPE_INNER = "INNER";
const TYPE_FULL = "FULL";
const TYPE_CROSS = "CROSS";
const TYPE_NATURAL = "NATURAL";
public bool $outer = false;
public array $joins = [];
public string $attachment = "ON";
public string $side;
public /*string|QueryBuilder*/ $table;
public ? string $alias;
public string $field;
public /*string|QueryBuilder*/ $value;
public /* QueryBuilder */ $queryBuilder;
public function __construct(QueryBuilder $queryBuilder)
{
$this->queryBuilder = new QueryBuilder();
$this->queryBuilder->parent = $queryBuilder;
}
public function set(string $side, /* QueryBuilder|string */ $table, string $field, /* QueryBuilder|string */ $value)
{
$this->side = $side;
$this->table = $table;
$this->field = $field;
$this->value = $value;
}
public function render() : string
{
if ($this->queryBuilder->where ?? false ) {
$where = $this->renderSegments([Where::CONDITION_AND, $this->queryBuilder->render(true)]);
}
return $this->renderSegments([
strtoupper($this->side), $this->outer ? static::SQL_OUTER : "", static::SQL_TOKEN, $this->table, $this->alias ?? "", $this->attachment, $this->field, "=", $this->value, $where ?? ""
]);
}
}