|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright 2021 Aleksandar Panic |
|
4
|
|
|
* |
|
5
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
6
|
|
|
* you may not use this file except in compliance with the License. |
|
7
|
|
|
* You may obtain a copy of the License at |
|
8
|
|
|
* |
|
9
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0 |
|
10
|
|
|
* |
|
11
|
|
|
* Unless required by applicable law or agreed to in writing, software |
|
12
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, |
|
13
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
14
|
|
|
* See the License for the specific language governing permissions and |
|
15
|
|
|
* limitations under the License. |
|
16
|
|
|
*/ |
|
17
|
|
|
|
|
18
|
|
|
namespace ArekX\PQL\Sql\Query; |
|
19
|
|
|
|
|
20
|
|
|
use ArekX\PQL\Contracts\GroupedSubQuery; |
|
21
|
|
|
use ArekX\PQL\Contracts\StructuredQuery; |
|
22
|
|
|
use ArekX\PQL\Query; |
|
23
|
|
|
use ArekX\PQL\Sql\Query\Traits\ConfigureTrait; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Represents an union query |
|
27
|
|
|
* for union of multiple queries. |
|
28
|
|
|
*/ |
|
29
|
|
|
class Union extends Query implements GroupedSubQuery |
|
30
|
|
|
{ |
|
31
|
|
|
use ConfigureTrait; |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* Set initial query to union other |
|
35
|
|
|
* queries with. |
|
36
|
|
|
* |
|
37
|
|
|
* @param StructuredQuery $from Query to be used. |
|
38
|
|
|
* @return $this |
|
39
|
|
|
*/ |
|
40
|
5 |
|
public function from(StructuredQuery $from): static |
|
41
|
|
|
{ |
|
42
|
5 |
|
$this->use('from', $from); |
|
43
|
5 |
|
return $this; |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Append union to the current |
|
48
|
|
|
* |
|
49
|
|
|
* @param StructuredQuery $query Query to be used. |
|
50
|
|
|
* @param string|null $type Type of the union. If null, means no specific type. |
|
51
|
|
|
* @return $this |
|
52
|
|
|
*/ |
|
53
|
5 |
|
public function unionWith(StructuredQuery $query, string $type = null): static |
|
54
|
|
|
{ |
|
55
|
5 |
|
$this->append('union', [$query, $type]); |
|
56
|
5 |
|
return $this; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|