1 | <?php |
||
23 | class SelectQuery extends AbstractSelect implements \JsonSerializable |
||
24 | { |
||
25 | /** |
||
26 | * Table names to select data from. |
||
27 | * |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $tables = []; |
||
31 | |||
32 | /** |
||
33 | * Select queries represented by sql fragments or query builders to be united. Stored as |
||
34 | * [UNION TYPE, SELECT QUERY]. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $unionTokens = []; |
||
39 | |||
40 | /** |
||
41 | * {@inheritdoc} |
||
42 | * |
||
43 | * @param array $from Initial set of table names. |
||
44 | * @param array $columns Initial set of columns to fetch. |
||
45 | */ |
||
46 | public function __construct( |
||
59 | |||
60 | /** |
||
61 | * Set table names SELECT query should be performed for. Table names can be provided with |
||
62 | * specified alias (AS construction). |
||
63 | * |
||
64 | * @param array|string|mixed $tables Array of names, comma separated string or set of |
||
65 | * parameters. |
||
66 | * |
||
67 | * @return self|$this |
||
68 | */ |
||
69 | public function from($tables): SelectQuery |
||
75 | |||
76 | /** |
||
77 | * Set columns should be fetched as result of SELECT query. Columns can be provided with |
||
78 | * specified alias (AS construction). |
||
79 | * |
||
80 | * @param array|string|mixed $columns Array of names, comma separated string or set of |
||
81 | * parameters. |
||
82 | * |
||
83 | * @return self|$this |
||
84 | */ |
||
85 | public function columns($columns): SelectQuery |
||
91 | |||
92 | /** |
||
93 | * Alias for columns() method. |
||
94 | * |
||
95 | * @param array|string|mixed $columns Array of names, comma separated string or set of |
||
96 | * parameters. |
||
97 | * |
||
98 | * @return self|$this |
||
99 | */ |
||
100 | public function select($columns): SelectQuery |
||
106 | |||
107 | /** |
||
108 | * Add select query to be united with. |
||
109 | * |
||
110 | * @param FragmentInterface $query |
||
111 | * |
||
112 | * @return self|$this |
||
113 | */ |
||
114 | public function union(FragmentInterface $query): SelectQuery |
||
120 | |||
121 | /** |
||
122 | * Add select query to be united with. Duplicate values will be included in result. |
||
123 | * |
||
124 | * @param FragmentInterface $query |
||
125 | * |
||
126 | * @return self|$this |
||
127 | */ |
||
128 | public function unionAll(FragmentInterface $query): SelectQuery |
||
134 | |||
135 | /** |
||
136 | * {@inheritdoc} |
||
137 | */ |
||
138 | public function getParameters(QueryCompiler $compiler = null): array |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | * |
||
157 | * @param bool $paginate Apply pagination to result, can be disabled in honor of count method. |
||
158 | * |
||
159 | * @return PDOResult |
||
160 | */ |
||
161 | public function run(bool $paginate = true) |
||
186 | |||
187 | /** |
||
188 | * Iterate thought result using smaller data chinks with defined size and walk function. |
||
189 | * |
||
190 | * Example: |
||
191 | * $select->chunked(100, function(PDOResult $result, $offset, $count) { |
||
192 | * dump($result); |
||
193 | * }); |
||
194 | * |
||
195 | * You must return FALSE from walk function to stop chunking. |
||
196 | * |
||
197 | * @param int $limit |
||
198 | * @param callable $callback |
||
199 | */ |
||
200 | public function runChunks(int $limit, callable $callback) |
||
224 | |||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | * |
||
228 | * Count number of rows in query. Limit, offset, order by, group by values will be ignored. Do |
||
229 | * not count united queries, or queries in complex joins. |
||
230 | * |
||
231 | * @param string $column Column to count by (every column by default). |
||
232 | * |
||
233 | * @return int |
||
234 | */ |
||
235 | public function count(string $column = '*'): int |
||
247 | |||
248 | /** |
||
249 | * {@inheritdoc} |
||
250 | * |
||
251 | * Shortcut to execute one of aggregation methods (AVG, MAX, MIN, SUM) using method name as |
||
252 | * reference. |
||
253 | * |
||
254 | * Example: |
||
255 | * echo $select->sum('user.balance'); |
||
256 | * |
||
257 | * @param string $method |
||
258 | * @param array $arguments |
||
259 | * |
||
260 | * @return int|float |
||
261 | * |
||
262 | * @throws BuilderException |
||
263 | * @throws QueryException |
||
264 | */ |
||
265 | public function __call(string $method, array $arguments) |
||
291 | |||
292 | /** |
||
293 | * {@inheritdoc} |
||
294 | * |
||
295 | * @return \PDOStatement|PDOResult |
||
296 | */ |
||
297 | public function getIterator() |
||
301 | |||
302 | /** |
||
303 | * {@inheritdoc} |
||
304 | */ |
||
305 | public function sqlStatement(QueryCompiler $compiler = null): string |
||
326 | |||
327 | /** |
||
328 | * {@inheritdoc} |
||
329 | */ |
||
330 | public function jsonSerialize() |
||
334 | |||
335 | /** |
||
336 | * Request all results as array. |
||
337 | * |
||
338 | * @return array |
||
339 | */ |
||
340 | public function fetchAll(): array |
||
344 | } |
||
345 |