-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSqlQueryInterface.php
More file actions
238 lines (218 loc) · 6.42 KB
/
Copy pathSqlQueryInterface.php
File metadata and controls
238 lines (218 loc) · 6.42 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
namespace Bdf\Prime\Query;
use Bdf\Prime\Exception\PrimeException;
use Bdf\Prime\Query\Contract\Aggregatable;
use Bdf\Prime\Query\Contract\EntityJoinable;
use Bdf\Prime\Query\Contract\Joinable;
use Bdf\Prime\Query\Contract\Limitable;
use Bdf\Prime\Query\Contract\Lockable;
use Bdf\Prime\Query\Contract\Orderable;
use Bdf\Prime\Query\Expression\Raw;
use Doctrine\DBAL\Query\Expression\CompositeExpression;
/**
* Interface for SQL queries
*
* @template C as \Bdf\Prime\Connection\ConnectionInterface
* @template R as object|array
*
* @extends QueryInterface<C, R>
*/
interface SqlQueryInterface extends QueryInterface, Aggregatable, Limitable, Orderable, Joinable, Lockable, EntityJoinable
{
/**
* {@inheritdoc}
*
* Gets all defined query bindings for the query being constructed indexed by parameter index or name.
*
* @return array The currently defined query parameters indexed by parameter index or name.
*/
public function getBindings(): array;
/**
* Specifies a grouping over the results of the query.
* Replaces any previously specified groupings, if any.
*
* <code>
* $query->group('u.id'); // GROUP BY u.id
* $query->group('u.id', 'name'); // GROUP BY u.id, name
* </code>
*
* @param string ...$columns The grouping columns.
*
* @return $this This Query instance.
*/
public function group(string ...$columns);
/**
* Add a grouping over the results of the query.
*
* <code>
* $query->addGroup('u.id'); // GROUP BY u.id
* $query->addGroup('u.date', 'name'); // GROUP BY u.id, u.date, name
* </code>
*
* @param string ...$columns The grouping columns.
*
* @return $this This Query instance.
* @no-named-arguments
*/
public function addGroup(string ...$columns);
/**
* Specifies a restriction over the groups of the query.
* Replaces any previous having restrictions, if any.
*
* @param string|array<string,mixed>|callable(static):void $column The restriction predicates.
* @param string|mixed|null $operator The comparison operator, or the value is you want to use "=" operator
* @param mixed $value
*
* @return $this This Query instance.
*
* @see where()
*/
public function having($column, $operator = null, $value = null);
/**
* Adds a restriction over the groups of the query, forming a logical
* disjunction with any existing having restrictions.
*
* @param string|array<string,mixed>|callable(static):void $column The restriction predicates.
* @param string|mixed|null $operator The comparison operator, or the value is you want to use "=" operator
* @param mixed $value
*
* @return $this This Query instance.
*
* @see having()
*/
public function orHaving($column, $operator = null, $value = null);
/**
* Add having IS NULL expression
*
* @param string $column
* @param string $type
*
* @return $this This Query instance.
*/
public function havingNull(string $column, string $type = CompositeExpression::TYPE_AND);
/**
* Add having IS NOT NULL expression
*
* @param string $column
* @param string $type
*
* @return $this This Query instance.
*/
public function havingNotNull(string $column, string $type = CompositeExpression::TYPE_AND);
/**
* Add OR having IS NULL expression
*
* @param string $column
*
* @return $this This Query instance.
*/
public function orHavingNull(string $column);
/**
* Add OR having IS NOT NULL expression
*
* @param string $column
*
* @return $this This Query instance.
*/
public function orHavingNotNull(string $column);
/**
* Add having SQL expression
*
* @param string|\Bdf\Prime\Query\QueryInterface|\Bdf\Prime\Query\Expression\ExpressionInterface $raw
* @param string $type
*
* @return $this This Query instance.
*/
public function havingRaw($raw, string $type = CompositeExpression::TYPE_AND);
/**
* Add OR having SQL expression
*
* @param string|\Bdf\Prime\Query\QueryInterface|\Bdf\Prime\Query\Expression\ExpressionInterface $raw
*
* @return $this This Query instance.
*/
public function orHavingRaw($raw);
/**
* Add key word IGNORE on insert
*
* <code>
* $query
* ->from('users')
* ->setValue('password', 'bar', 'string')
* ->ignore()
* ->insert();
* </code>
*
* @param bool $flag
*
* @return $this
*/
public function ignore(bool $flag = true);
/**
* Add key word DISTINCT on select
*
* <code>
* $query
* ->select('u.id')
* ->distinct()
* ->from('users', 'u');
* </code>
*
* @param bool $flag
*
* @return $this This Query instance.
*/
public function distinct(bool $flag = true);
/**
* Quote a value
*
* @param scalar $value
* @param \Doctrine\DBAL\ParameterType::* $type
*
* @return string
* @throws PrimeException
*/
public function quote($value, ?int $type = null): string;
/**
* Quote a identifier
*
* @param string $column
*
* @return string
* @throws PrimeException
*/
public function quoteIdentifier(string $column): string;
/**
* Get the count of the query for pagination
*
* @param string|null $column
*
* @return int
* @throws PrimeException When execute fail
*/
public function paginationCount(?string $column = null): int;
/**
* Gets the complete SQL string formed by the current specifications of this query.
*
* <code>
* $query
* ->select('*')
* ->from('User', 'u')
* echo $query->toSql(); // SELECT * FROM User u
* </code>
*
* @return string The SQL query string.
* @throws PrimeException When compilation fail
*/
public function toSql(): string;
/**
* Return SQL representation of the query with bindings
* Works like `toSql()` but replace placeholders by bound values
*
* @return string
*
* @todo A reprendre: utiliser les types des bindings
* @throws PrimeException When compilation fail
*/
public function toRawSql(): string;
}