Issues (590)

src/Query/SqlQueryInterface.php (1 issue)

1
<?php
2
3
namespace Bdf\Prime\Query;
4
5
use Bdf\Prime\Exception\PrimeException;
6
use Bdf\Prime\Query\Contract\Aggregatable;
7
use Bdf\Prime\Query\Contract\EntityJoinable;
8
use Bdf\Prime\Query\Contract\Joinable;
9
use Bdf\Prime\Query\Contract\Limitable;
10
use Bdf\Prime\Query\Contract\Lockable;
11
use Bdf\Prime\Query\Contract\Orderable;
12
use Bdf\Prime\Query\Expression\Raw;
13
use Doctrine\DBAL\Query\Expression\CompositeExpression;
14
15
/**
16
 * Interface for SQL queries
17
 *
18
 * @template C as \Bdf\Prime\Connection\ConnectionInterface
19
 * @template R as object|array
20
 *
21
 * @extends QueryInterface<C, R>
22
 */
23
interface SqlQueryInterface extends QueryInterface, Aggregatable, Limitable, Orderable, Joinable, Lockable, EntityJoinable
24
{
25
    /**
26
     * {@inheritdoc}
27
     *
28
     * Gets all defined query bindings for the query being constructed indexed by parameter index or name.
29
     *
30
     * @return array The currently defined query parameters indexed by parameter index or name.
31
     */
32
    public function getBindings(): array;
33
34
    /**
35
     * Specifies a grouping over the results of the query.
36
     * Replaces any previously specified groupings, if any.
37
     *
38
     * <code>
39
     *     $query->group('u.id'); // GROUP BY u.id
40
     *     $query->group('u.id', 'name'); // GROUP BY u.id, name
41
     * </code>
42
     *
43
     * @param string ...$columns The grouping columns.
44
     *
45
     * @return $this This Query instance.
46
     */
47
    public function group(string ...$columns);
48
49
    /**
50
     * Add a grouping over the results of the query.
51
     *
52
     * <code>
53
     *     $query->addGroup('u.id'); // GROUP BY u.id
54
     *     $query->addGroup('u.date', 'name'); // GROUP BY u.id, u.date, name
55
     * </code>
56
     *
57
     * @param string ...$columns The grouping columns.
58
     *
59
     * @return $this This Query instance.
60
     * @no-named-arguments
61
     */
62
    public function addGroup(string ...$columns);
63
64
    /**
65
     * Specifies a restriction over the groups of the query.
66
     * Replaces any previous having restrictions, if any.
67
     *
68
     * @param string|array<string,mixed>|callable(static):void $column The restriction predicates.
69
     * @param string|mixed|null $operator The comparison operator, or the value is you want to use "=" operator
70
     * @param mixed $value
71
     *
72
     * @return $this This Query instance.
73
     *
74
     * @see where()
75
     */
76
    public function having($column, $operator = null, $value = null);
77
78
    /**
79
     * Adds a restriction over the groups of the query, forming a logical
80
     * disjunction with any existing having restrictions.
81
     *
82
     * @param string|array<string,mixed>|callable(static):void $column The restriction predicates.
83
     * @param string|mixed|null $operator The comparison operator, or the value is you want to use "=" operator
84
     * @param mixed $value
85
     *
86
     * @return $this This Query instance.
87
     *
88
     * @see having()
89
     */
90
    public function orHaving($column, $operator = null, $value = null);
91
92
    /**
93
     * Add having IS NULL expression
94
     *
95
     * @param string $column
96
     * @param string $type
97
     *
98
     * @return $this This Query instance.
99
     */
100
    public function havingNull(string $column, string $type = CompositeExpression::TYPE_AND);
101
102
    /**
103
     * Add having IS NOT NULL expression
104
     *
105
     * @param string $column
106
     * @param string $type
107
     *
108
     * @return $this This Query instance.
109
     */
110
    public function havingNotNull(string $column, string $type = CompositeExpression::TYPE_AND);
111
112
    /**
113
     * Add OR having IS NULL expression
114
     *
115
     * @param string $column
116
     *
117
     * @return $this This Query instance.
118
     */
119
    public function orHavingNull(string $column);
120
121
    /**
122
     * Add OR having IS NOT NULL expression
123
     *
124
     * @param string $column
125
     *
126
     * @return $this This Query instance.
127
     */
128
    public function orHavingNotNull(string $column);
129
130
    /**
131
     * Add having SQL expression
132
     *
133
     * @param string|\Bdf\Prime\Query\QueryInterface|\Bdf\Prime\Query\Expression\ExpressionInterface $raw
134
     * @param string $type
135
     *
136
     * @return $this This Query instance.
137
     */
138
    public function havingRaw($raw, string $type = CompositeExpression::TYPE_AND);
139
140
    /**
141
     * Add OR having SQL expression
142
     *
143
     * @param string|\Bdf\Prime\Query\QueryInterface|\Bdf\Prime\Query\Expression\ExpressionInterface $raw
144
     *
145
     * @return $this This Query instance.
146
     */
147
    public function orHavingRaw($raw);
148
149
    /**
150
     * Add key word IGNORE on insert
151
     *
152
     * <code>
153
     *     $query
154
     *         ->from('users')
155
     *         ->setValue('password', 'bar', 'string')
156
     *         ->ignore()
157
     *         ->insert();
158
     * </code>
159
     *
160
     * @param bool $flag
161
     *
162
     * @return $this
163
     */
164
    public function ignore(bool $flag = true);
165
166
    /**
167
     * Add key word DISTINCT on select
168
     *
169
     * <code>
170
     *     $query
171
     *         ->select('u.id')
172
     *         ->distinct()
173
     *         ->from('users', 'u');
174
     * </code>
175
     *
176
     * @param bool $flag
177
     *
178
     * @return $this This Query instance.
179
     */
180
    public function distinct(bool $flag = true);
181
182
    /**
183
     * Quote a value
184
     *
185
     * @param scalar $value
186
     * @param \Doctrine\DBAL\ParameterType::* $type
0 ignored issues
show
Documentation Bug introduced by
The doc comment $type at position 0 could not be parsed: Unknown type name '$type' at position 0 in $type.
Loading history...
187
     *
188
     * @return string
189
     * @throws PrimeException
190
     */
191
    public function quote($value, int $type = null): string;
192
193
    /**
194
     * Quote a identifier
195
     *
196
     * @param string $column
197
     *
198
     * @return string
199
     * @throws PrimeException
200
     */
201
    public function quoteIdentifier(string $column): string;
202
203
    /**
204
     * Get the count of the query for pagination
205
     *
206
     * @param string|null $column
207
     *
208
     * @return int
209
     * @throws PrimeException When execute fail
210
     */
211
    public function paginationCount(?string $column = null): int;
212
213
    /**
214
     * Gets the complete SQL string formed by the current specifications of this query.
215
     *
216
     * <code>
217
     *     $query
218
     *         ->select('*')
219
     *         ->from('User', 'u')
220
     *     echo $query->toSql(); // SELECT * FROM User u
221
     * </code>
222
     *
223
     * @return string The SQL query string.
224
     * @throws PrimeException When compilation fail
225
     */
226
    public function toSql(): string;
227
228
    /**
229
     * Return SQL representation of the query with bindings
230
     * Works like `toSql()` but replace placeholders by bound values
231
     *
232
     * @return string
233
     *
234
     * @todo A reprendre: utiliser les types des bindings
235
     * @throws PrimeException When compilation fail
236
     */
237
    public function toRawSql(): string;
238
}
239