-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJoinable.php
More file actions
104 lines (99 loc) · 4.21 KB
/
Copy pathJoinable.php
File metadata and controls
104 lines (99 loc) · 4.21 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
namespace Bdf\Prime\Query\Contract;
/**
* Interface for join() methods
*/
interface Joinable
{
// join type
public const INNER_JOIN = 'INNER';
public const LEFT_JOIN = 'LEFT';
public const RIGHT_JOIN = 'RIGHT';
/**
* Creates and adds a join to the query.
*
* Simple usage:
* <code>
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->join(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
* </code>
*
* With subQuery:
* <code>
* $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->join([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
* </code>
*
* @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
* @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
* @param string|null $operator If $key is a string, the matching operator
* @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
* @param Joinable::* $type Type of join.
*
* @return $this This Query instance.
*/
public function join($table, $key, ?string $operator = null, $foreign = null, string $type = self::INNER_JOIN);
/**
* Creates and adds a left join to the query.
* This is equivalent to call join() with type LEFT_JOIN as last parameter
*
* Simple usage:
* <code>
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->leftJoin(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
* </code>
*
* With subQuery:
* <code>
* $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->leftJoin([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
* </code>
*
* @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
* @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
* @param string|null $operator If $key is a string, the matching operator
* @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
*
* @return $this This Query instance.
*/
public function leftJoin($table, $key, ?string $operator = null, $foreign = null);
/**
* Creates and adds a right join to the query.
* This is equivalent to call join() with type RIGHT_JOIN as last parameter
*
* Simple usage:
* <code>
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->leftJoin(['phonenumbers', 'p'], 'p.id', '=', new Attribute('u.id'));
* </code>
*
* With subQuery:
* <code>
* $subQuery = MyEntity::builder()->select(['bar' => 'foo'])->where(...);
* $query
* ->select('u.name')
* ->from('users', 'u')
* ->leftJoin([$subQuery, 's'], 's.bar', '=', new Attribute('u.id'));
* </code>
*
* @param string|\Bdf\Prime\Query\QueryInterface|array $table The joined table. Can also be a sub query. To defined an alias, use syntax [$table, $alias]
* @param string|callable(\Bdf\Prime\Query\JoinClause):void $key The local key (fk), or the join clause configurator
* @param string|null $operator If $key is a string, the matching operator
* @param mixed|\Bdf\Prime\Query\Expression\ExpressionInterface|null $foreign If $key is a string, the foreign key value. Use new Attribute() to match with an attribute
*
* @return $this This Query instance.
*/
public function rightJoin($table, $key, ?string $operator = null, $foreign = null);
}