1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kalanis\kw_mapper\Storage\Database\Dialects; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
use kalanis\kw_mapper\MapperException; |
7
|
|
|
use kalanis\kw_mapper\Storage\Shared\QueryBuilder; |
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Trait TDialectProps |
12
|
|
|
* @package kalanis\kw_mapper\Storage\Database\Dialects |
13
|
|
|
* To load correct dialect's fillers from tree |
14
|
|
|
*/ |
15
|
|
|
trait TDialectProps |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @param QueryBuilder\Column[] $columns |
19
|
|
|
* @return string |
20
|
|
|
*/ |
21
|
23 |
|
public function makeSimpleColumns(array $columns): string |
22
|
|
|
{ |
23
|
23 |
|
if (empty($columns)) { |
24
|
4 |
|
return $this->selectAllColumns(); |
25
|
|
|
} |
26
|
19 |
|
return implode(', ', array_map([$this, 'singleSimpleColumn'], $columns)); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param QueryBuilder\Column[] $columns |
31
|
|
|
* @return string |
32
|
|
|
*/ |
33
|
16 |
|
public function makeFullColumns(array $columns): string |
34
|
|
|
{ |
35
|
16 |
|
if (empty($columns)) { |
36
|
3 |
|
return $this->selectAllColumns(); |
37
|
|
|
} |
38
|
13 |
|
return implode(', ', array_map([$this, 'singleFullColumn'], $columns)); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
abstract protected function selectAllColumns(): string; |
42
|
|
|
|
43
|
|
|
abstract public function singleSimpleColumn(QueryBuilder\Column $column): string; |
44
|
|
|
|
45
|
|
|
abstract public function singleFullColumn(QueryBuilder\Column $column): string; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param QueryBuilder\Property[] $properties |
49
|
|
|
* @return string |
50
|
|
|
*/ |
51
|
17 |
|
public function makeProperty(array $properties): string |
52
|
|
|
{ |
53
|
17 |
|
if (empty($properties)) { |
54
|
3 |
|
return $this->selectAllProperties(); |
55
|
|
|
} |
56
|
14 |
|
return implode(', ', array_map([$this, 'singleProperty'], $properties)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
abstract protected function selectAllProperties(): string; |
60
|
|
|
|
61
|
|
|
abstract public function singleProperty(QueryBuilder\Property $column): string; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param QueryBuilder\Property[] $properties |
65
|
|
|
* @throws MapperException |
66
|
|
|
* @return string |
67
|
|
|
*/ |
68
|
16 |
|
public function makeSimplePropertyList(array $properties): string |
69
|
|
|
{ |
70
|
16 |
|
if (empty($properties)) { |
71
|
3 |
|
throw new MapperException('Empty property list!'); |
72
|
|
|
} |
73
|
13 |
|
return implode(', ', array_map([$this, 'singleSimplePropertyListed'], $properties)); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
abstract public function singleSimplePropertyListed(QueryBuilder\Property $column): string; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param QueryBuilder\Property[] $properties |
80
|
|
|
* @throws MapperException |
81
|
|
|
* @return string |
82
|
|
|
*/ |
83
|
6 |
|
public function makeFullPropertyList(array $properties): string |
84
|
|
|
{ |
85
|
6 |
|
if (empty($properties)) { |
86
|
3 |
|
throw new MapperException('Empty property list!'); |
87
|
|
|
} |
88
|
3 |
|
return implode(', ', array_map([$this, 'singleFullPropertyListed'], $properties)); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
abstract public function singleFullPropertyListed(QueryBuilder\Property $column): string; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param QueryBuilder\Property[] $properties |
95
|
|
|
* @throws MapperException |
96
|
|
|
* @return string |
97
|
|
|
*/ |
98
|
16 |
|
public function makePropertyEntries(array $properties): string |
99
|
|
|
{ |
100
|
16 |
|
if (empty($properties)) { |
101
|
3 |
|
throw new MapperException('Empty property list!'); |
102
|
|
|
} |
103
|
13 |
|
return implode(', ', array_map([$this, 'singlePropertyEntry'], $properties)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
abstract public function singlePropertyEntry(QueryBuilder\Property $column): string; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @param QueryBuilder\Condition[] $conditions |
110
|
|
|
* @param string $relation |
111
|
|
|
* @return string |
112
|
|
|
*/ |
113
|
35 |
|
public function makeSimpleConditions(array $conditions, string $relation): string |
114
|
|
|
{ |
115
|
35 |
|
if (empty($conditions)) { |
116
|
11 |
|
return ''; |
117
|
|
|
} |
118
|
31 |
|
return ' WHERE ' . implode(' ' . $relation . ' ', array_map([$this, 'singleSimpleCondition'], $conditions)); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
/** |
122
|
|
|
* @param QueryBuilder\Condition[] $conditions |
123
|
|
|
* @param string $relation |
124
|
|
|
* @return string |
125
|
|
|
*/ |
126
|
18 |
|
public function makeFullConditions(array $conditions, string $relation): string |
127
|
|
|
{ |
128
|
18 |
|
if (empty($conditions)) { |
129
|
4 |
|
return ''; |
130
|
|
|
} |
131
|
15 |
|
return ' WHERE ' . implode(' ' . $relation . ' ', array_map([$this, 'singleFullCondition'], $conditions)); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* @param QueryBuilder\Condition[] $conditions |
136
|
|
|
* @param string $relation |
137
|
|
|
* @return string |
138
|
|
|
*/ |
139
|
23 |
|
public function makeSimpleHaving(array $conditions, string $relation): string |
140
|
|
|
{ |
141
|
23 |
|
if (empty($conditions)) { |
142
|
20 |
|
return ''; |
143
|
|
|
} |
144
|
4 |
|
return ' HAVING ' . implode(' ' . $relation . ' ', array_map([$this, 'singleSimpleCondition'], $conditions)); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @param QueryBuilder\Condition[] $conditions |
149
|
|
|
* @param string $relation |
150
|
|
|
* @return string |
151
|
|
|
*/ |
152
|
16 |
|
public function makeFullHaving(array $conditions, string $relation): string |
153
|
|
|
{ |
154
|
16 |
|
if (empty($conditions)) { |
155
|
13 |
|
return ''; |
156
|
|
|
} |
157
|
3 |
|
return ' HAVING ' . implode(' ' . $relation . ' ', array_map([$this, 'singleFullCondition'], $conditions)); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @param QueryBuilder\Condition $condition |
162
|
|
|
* @throws MapperException |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
abstract public function singleSimpleCondition(QueryBuilder\Condition $condition): string; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @param QueryBuilder\Condition $condition |
169
|
|
|
* @throws MapperException |
170
|
|
|
* @return string |
171
|
|
|
*/ |
172
|
|
|
abstract public function singleFullCondition(QueryBuilder\Condition $condition): string; |
173
|
|
|
|
174
|
|
|
/** |
175
|
|
|
* @param QueryBuilder\Order[] $ordering |
176
|
|
|
* @return string |
177
|
|
|
*/ |
178
|
23 |
|
public function makeSimpleOrdering(array $ordering): string |
179
|
|
|
{ |
180
|
23 |
|
if (empty($ordering)) { |
181
|
18 |
|
return ''; |
182
|
|
|
} |
183
|
10 |
|
return ' ORDER BY ' . implode(', ', array_map([$this, 'singleSimpleOrder'], $ordering)); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
abstract public function singleSimpleOrder(QueryBuilder\Order $order): string; |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param QueryBuilder\Order[] $ordering |
190
|
|
|
* @return string |
191
|
|
|
*/ |
192
|
16 |
|
public function makeFullOrdering(array $ordering): string |
193
|
|
|
{ |
194
|
16 |
|
if (empty($ordering)) { |
195
|
8 |
|
return ''; |
196
|
|
|
} |
197
|
12 |
|
return ' ORDER BY ' . implode(', ', array_map([$this, 'singleFullOrder'], $ordering)); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
abstract public function singleFullOrder(QueryBuilder\Order $order): string; |
201
|
|
|
|
202
|
|
|
/** |
203
|
|
|
* @param QueryBuilder\Group[] $groups |
204
|
|
|
* @return string |
205
|
|
|
*/ |
206
|
23 |
|
public function makeSimpleGrouping(array $groups): string |
207
|
|
|
{ |
208
|
23 |
|
if (empty($groups)) { |
209
|
18 |
|
return ''; |
210
|
|
|
} |
211
|
5 |
|
return ' GROUP BY ' . implode(', ', array_map([$this, 'singleSimpleGroup'], $groups)); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
abstract public function singleSimpleGroup(QueryBuilder\Group $group): string; |
215
|
|
|
|
216
|
|
|
/** |
217
|
|
|
* @param QueryBuilder\Group[] $groups |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
16 |
|
public function makeFullGrouping(array $groups): string |
221
|
|
|
{ |
222
|
16 |
|
if (empty($groups)) { |
223
|
8 |
|
return ''; |
224
|
|
|
} |
225
|
8 |
|
return ' GROUP BY ' . implode(', ', array_map([$this, 'singleFullGroup'], $groups)); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
abstract public function singleFullGroup(QueryBuilder\Group $group): string; |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* @param QueryBuilder\Join[] $join |
232
|
|
|
* @return string |
233
|
|
|
*/ |
234
|
16 |
|
public function makeJoin(array $join): string |
235
|
|
|
{ |
236
|
16 |
|
if (empty($join)) { |
237
|
6 |
|
return ''; |
238
|
|
|
} |
239
|
10 |
|
return implode(' ', array_map([$this, 'singleJoin'], $join)); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
abstract public function singleJoin(QueryBuilder\Join $join): string; |
243
|
|
|
} |
244
|
|
|
|