-
Notifications
You must be signed in to change notification settings - Fork 31
/
BuilderLateralJoin.php
60 lines (47 loc) · 1.85 KB
/
BuilderLateralJoin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
declare(strict_types=1);
namespace Tpetry\PostgresqlEnhanced\Query;
use Illuminate\Database\Query\Expression;
trait BuilderLateralJoin
{
/**
* Add a lateral subquery cross join to the query.
*
* @param \Closure|\Illuminate\Contracts\Database\Query\Builder|string $query
*/
public function crossJoinSubLateral($query, string $as): static
{
[$query, $bindings] = $this->createSub($query);
$expression = new Expression("lateral ({$query}) as {$this->grammar->wrapTable($as)}");
$this->addBinding($bindings, 'join');
$this->joins[] = $this->newJoinClause($this, 'cross', $expression);
return $this;
}
/**
* Add a lateral subquery join clause to the query.
*
* @param \Closure|\Illuminate\Contracts\Database\Query\Builder|string $query
* @param \Closure|string $first
* @param string|null $operator
* @param string|null $second
*/
public function joinSubLateral($query, string $as, $first, $operator = null, $second = null, string $type = 'inner', bool $where = false): static
{
[$query, $bindings] = $this->createSub($query);
$expression = new Expression("lateral ({$query}) as {$this->grammar->wrapTable($as)}");
$this->addBinding($bindings, 'join');
return $this->join($expression, $first, $operator, $second, $type, $where);
}
/**
* Add a lateral subquery left join to the query.
*
* @param \Closure|\Illuminate\Contracts\Database\Query\Builder|string $query
* @param \Closure|string|null $first
* @param string|null $operator
* @param string|null $second
*/
public function leftJoinSubLateral($query, string $as, $first = null, $operator = null, $second = null): static
{
return $this->joinSubLateral($query, $as, $first, $operator, $second, 'left');
}
}