kysely 0.12.0 → 0.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/dialect/dialect-adapter-base.d.ts +36 -0
- package/dist/cjs/dialect/mysql/mysql-adapter.d.ts +36 -0
- package/dist/cjs/dialect/mysql/mysql-dialect.d.ts +16 -0
- package/dist/cjs/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/cjs/dialect/mysql/mysql-introspector.d.ts +3 -0
- package/dist/cjs/dialect/postgres/postgres-adapter.d.ts +36 -0
- package/dist/cjs/dialect/postgres/postgres-dialect.d.ts +16 -0
- package/dist/cjs/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/cjs/dialect/postgres/postgres-introspector.d.ts +3 -0
- package/dist/cjs/dialect/sqlite/sqlite-adapter.d.ts +36 -0
- package/dist/cjs/dialect/sqlite/sqlite-dialect.d.ts +16 -0
- package/dist/cjs/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/cjs/dialect/sqlite/sqlite-introspector.d.ts +3 -0
- package/dist/cjs/driver/default-connection-provider.d.ts +4 -0
- package/dist/cjs/driver/runtime-driver.d.ts +29 -0
- package/dist/cjs/driver/single-connection-provider.d.ts +4 -0
- package/dist/cjs/package.json +1 -3
- package/dist/cjs/parser/parse-context.d.ts +14 -0
- package/dist/cjs/plugin/camel-case/camel-case-plugin.d.ts +34 -0
- package/dist/cjs/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
- package/dist/cjs/plugin/with-schema/with-schema-plugin.d.ts +34 -0
- package/dist/cjs/query-builder/delete-query-builder.d.ts +545 -0
- package/dist/cjs/query-builder/insert-query-builder.d.ts +69 -4
- package/dist/cjs/query-builder/join-interface.d.ts +3 -6
- package/dist/cjs/query-builder/returning-interface.d.ts +1 -1
- package/dist/cjs/query-builder/select-query-builder.d.ts +513 -2
- package/dist/cjs/query-builder/select-query-builder.js +2 -2
- package/dist/cjs/query-builder/update-query-builder.d.ts +547 -2
- package/dist/cjs/query-builder/update-query-builder.js +2 -2
- package/dist/cjs/query-builder/where-interface.d.ts +7 -10
- package/dist/cjs/schema/alter-table-builder.d.ts +216 -0
- package/dist/cjs/schema/column-definition-builder.d.ts +108 -0
- package/dist/esm/dialect/dialect-adapter-base.d.ts +36 -0
- package/dist/esm/dialect/mysql/mysql-adapter.d.ts +36 -0
- package/dist/esm/dialect/mysql/mysql-dialect.d.ts +16 -0
- package/dist/esm/dialect/mysql/mysql-driver.d.ts +29 -0
- package/dist/esm/dialect/mysql/mysql-introspector.d.ts +3 -0
- package/dist/esm/dialect/postgres/postgres-adapter.d.ts +36 -0
- package/dist/esm/dialect/postgres/postgres-dialect.d.ts +16 -0
- package/dist/esm/dialect/postgres/postgres-driver.d.ts +29 -0
- package/dist/esm/dialect/postgres/postgres-introspector.d.ts +3 -0
- package/dist/esm/dialect/sqlite/sqlite-adapter.d.ts +36 -0
- package/dist/esm/dialect/sqlite/sqlite-dialect.d.ts +16 -0
- package/dist/esm/dialect/sqlite/sqlite-driver.d.ts +29 -0
- package/dist/esm/dialect/sqlite/sqlite-introspector.d.ts +3 -0
- package/dist/esm/driver/default-connection-provider.d.ts +4 -0
- package/dist/esm/driver/runtime-driver.d.ts +29 -0
- package/dist/esm/driver/single-connection-provider.d.ts +4 -0
- package/dist/esm/package.json +1 -3
- package/dist/esm/parser/parse-context.d.ts +14 -0
- package/dist/esm/plugin/camel-case/camel-case-plugin.d.ts +34 -0
- package/dist/esm/plugin/immediate-value.ts/immediate-value-plugin.d.ts +34 -0
- package/dist/esm/plugin/with-schema/with-schema-plugin.d.ts +34 -0
- package/dist/esm/query-builder/delete-query-builder.d.ts +545 -0
- package/dist/esm/query-builder/insert-query-builder.d.ts +69 -4
- package/dist/esm/query-builder/join-interface.d.ts +3 -6
- package/dist/esm/query-builder/returning-interface.d.ts +1 -1
- package/dist/esm/query-builder/select-query-builder.d.ts +513 -2
- package/dist/esm/query-builder/select-query-builder.js +2 -2
- package/dist/esm/query-builder/update-query-builder.d.ts +547 -2
- package/dist/esm/query-builder/update-query-builder.js +2 -2
- package/dist/esm/query-builder/where-interface.d.ts +7 -10
- package/dist/esm/schema/alter-table-builder.d.ts +216 -0
- package/dist/esm/schema/column-definition-builder.d.ts +108 -0
- package/package.json +7 -5
|
@@ -11,7 +11,7 @@ export interface ReturningInterface<DB, TB extends keyof DB, O> {
|
|
|
11
11
|
* [this bug](https://sqlite.org/forum/forumpost/033daf0b32) in SQLite.
|
|
12
12
|
* For example `.returning('id as id')`.
|
|
13
13
|
*
|
|
14
|
-
* Also see the {@link
|
|
14
|
+
* Also see the {@link returningAll} method.
|
|
15
15
|
*
|
|
16
16
|
* ### Examples
|
|
17
17
|
*
|
|
@@ -22,29 +22,422 @@ import { HavingInterface } from './having-interface.js';
|
|
|
22
22
|
export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, HavingInterface<DB, TB>, JoinInterface<DB, TB>, OperationNodeSource, Compilable {
|
|
23
23
|
#private;
|
|
24
24
|
constructor(props: SelectQueryBuilderProps);
|
|
25
|
+
/**
|
|
26
|
+
* Adds a `where` clause to the query.
|
|
27
|
+
*
|
|
28
|
+
* Also see {@link orWhere}, {@link whereExists} and {@link whereRef}.
|
|
29
|
+
*
|
|
30
|
+
* ### Examples
|
|
31
|
+
*
|
|
32
|
+
* Find a row by column value:
|
|
33
|
+
*
|
|
34
|
+
* ```ts
|
|
35
|
+
* const person = await db
|
|
36
|
+
* .selectFrom('person')
|
|
37
|
+
* .selectAll()
|
|
38
|
+
* .where('id', '=', 100)
|
|
39
|
+
* .executeTakeFirst()
|
|
40
|
+
* ```
|
|
41
|
+
*
|
|
42
|
+
* The generated SQL (PostgreSQL):
|
|
43
|
+
*
|
|
44
|
+
* ```sql
|
|
45
|
+
* select * from "person" where "id" = $1
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* Operator can be any supported operator or if the typings don't support it
|
|
49
|
+
* you can always use `db.raw('your operator')`.
|
|
50
|
+
*
|
|
51
|
+
* ```ts
|
|
52
|
+
* const persons = await db
|
|
53
|
+
* .selectFrom('person')
|
|
54
|
+
* .selectAll()
|
|
55
|
+
* .where('id', '>', 100)
|
|
56
|
+
* .execute()
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
* The generated SQL (PostgreSQL):
|
|
60
|
+
*
|
|
61
|
+
* ```sql
|
|
62
|
+
* select * from "person" where "id" > $1
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* The `where` methods don't change the type of the query. You can add
|
|
66
|
+
* conditional `where`s easily by doing something like this:
|
|
67
|
+
*
|
|
68
|
+
* ```ts
|
|
69
|
+
* let query = db
|
|
70
|
+
* .selectFrom('person')
|
|
71
|
+
* .selectAll()
|
|
72
|
+
*
|
|
73
|
+
* if (firstName) {
|
|
74
|
+
* query = query.where('first_name', '=', firstName)
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* const persons = await query.execute()
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* This is true for basically all methods execpt the `select` and
|
|
81
|
+
* `returning` methods, which DO change the return type of the
|
|
82
|
+
* query.
|
|
83
|
+
*
|
|
84
|
+
* Both the first and third argument can also be subqueries.
|
|
85
|
+
* A subquery is defined by passing a function and calling
|
|
86
|
+
* the `selectFrom` method of the object passed into the
|
|
87
|
+
* function:
|
|
88
|
+
*
|
|
89
|
+
* ```ts
|
|
90
|
+
* const persons = await db
|
|
91
|
+
* .selectFrom('person')
|
|
92
|
+
* .selectAll()
|
|
93
|
+
* .where(
|
|
94
|
+
* (qb) => qb.selectFrom('pet')
|
|
95
|
+
* .select('pet.name')
|
|
96
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
97
|
+
* .limit(1),
|
|
98
|
+
* '=',
|
|
99
|
+
* 'Fluffy'
|
|
100
|
+
* )
|
|
101
|
+
* .execute()
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* The generated SQL (PostgreSQL):
|
|
105
|
+
*
|
|
106
|
+
* ```sql
|
|
107
|
+
* select *
|
|
108
|
+
* from "person"
|
|
109
|
+
* where (
|
|
110
|
+
* select "pet"."name"
|
|
111
|
+
* from "pet"
|
|
112
|
+
* where "pet"."owner_id" = "person"."id"
|
|
113
|
+
* limit $1
|
|
114
|
+
* ) = $2
|
|
115
|
+
* ```
|
|
116
|
+
*
|
|
117
|
+
* A `where in` query can be built by using the `in` operator and an array
|
|
118
|
+
* of values. The values in the array can also be subqueries or raw
|
|
119
|
+
* instances.
|
|
120
|
+
*
|
|
121
|
+
* ```ts
|
|
122
|
+
* const persons = await db
|
|
123
|
+
* .selectFrom('person')
|
|
124
|
+
* .selectAll()
|
|
125
|
+
* .where('person.id', 'in', [100, 200, 300])
|
|
126
|
+
* .execute()
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* The generated SQL (PostgreSQL):
|
|
130
|
+
*
|
|
131
|
+
* ```sql
|
|
132
|
+
* select * from "person" where "id" in ($1, $2, $3)
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* If everything else fails, you can always pass {@link Kysely.raw | raw}
|
|
136
|
+
* as any of the arguments, including the operator:
|
|
137
|
+
*
|
|
138
|
+
* ```ts
|
|
139
|
+
* const persons = await db
|
|
140
|
+
* .selectFrom('person')
|
|
141
|
+
* .selectAll()
|
|
142
|
+
* .where(
|
|
143
|
+
* db.raw('coalesce(first_name, last_name)'),
|
|
144
|
+
* 'like',
|
|
145
|
+
* '%' + name + '%',
|
|
146
|
+
* )
|
|
147
|
+
* .execute()
|
|
148
|
+
* ```
|
|
149
|
+
*
|
|
150
|
+
* The generated SQL (PostgreSQL):
|
|
151
|
+
*
|
|
152
|
+
* ```sql
|
|
153
|
+
* select * from "person"
|
|
154
|
+
* where coalesce(first_name, last_name) like $1
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* If you only pass one function argument to this method, it can be
|
|
158
|
+
* used to create parentheses around other where statements:
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* const persons = await db
|
|
162
|
+
* .selectFrom('person')
|
|
163
|
+
* .selectAll()
|
|
164
|
+
* .where((qb) => qb
|
|
165
|
+
* .where('id', '=', 1)
|
|
166
|
+
* .orWhere('id', '=', 2)
|
|
167
|
+
* )
|
|
168
|
+
* .execute()
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* The generated SQL (PostgreSQL):
|
|
172
|
+
*
|
|
173
|
+
* ```sql
|
|
174
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
175
|
+
* ```
|
|
176
|
+
*
|
|
177
|
+
* In all examples above the columns were known at compile time
|
|
178
|
+
* (except for the `raw` expressions). By default kysely only allows
|
|
179
|
+
* you to refer to columns that exist in the database **and** can be
|
|
180
|
+
* referred to in the current query and context.
|
|
181
|
+
*
|
|
182
|
+
* Sometimes you may want to refer to columns that come from the user
|
|
183
|
+
* input and thus are not available at compile time.
|
|
184
|
+
*
|
|
185
|
+
* You have two options, `db.raw` or `db.dynamic`. The example below
|
|
186
|
+
* uses both:
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* const { ref } = db.dynamic
|
|
190
|
+
*
|
|
191
|
+
* const persons = await db
|
|
192
|
+
* .selectFrom('person')
|
|
193
|
+
* .selectAll()
|
|
194
|
+
* .where(ref(columnFromUserInput), '=', 1)
|
|
195
|
+
* .orWhere(db.raw('??', [columnFromUserInput]), '=', 2)
|
|
196
|
+
* .execute()
|
|
197
|
+
* ```
|
|
198
|
+
*/
|
|
25
199
|
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): SelectQueryBuilder<DB, TB, O>;
|
|
26
200
|
where(grouper: WhereGrouper<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
27
201
|
where(raw: AnyRawBuilder): SelectQueryBuilder<DB, TB, O>;
|
|
202
|
+
/**
|
|
203
|
+
* Adds a `where` clause where both sides of the operator are references
|
|
204
|
+
* to columns.
|
|
205
|
+
*
|
|
206
|
+
* The normal `where` method treats the right hand side argument as a
|
|
207
|
+
* value by default. `whereRef` treats it as a column reference. This method is
|
|
208
|
+
* expecially useful with joins and correclated subqueries.
|
|
209
|
+
*
|
|
210
|
+
* ### Examples
|
|
211
|
+
*
|
|
212
|
+
* Usage with a join:
|
|
213
|
+
*
|
|
214
|
+
* ```ts
|
|
215
|
+
* db.selectFrom(['person', 'pet'])
|
|
216
|
+
* .selectAll()
|
|
217
|
+
* .whereRef('person.first_name', '=', 'pet.name')
|
|
218
|
+
* ```
|
|
219
|
+
*
|
|
220
|
+
* The generated SQL (PostgreSQL):
|
|
221
|
+
*
|
|
222
|
+
* ```sql
|
|
223
|
+
* select * from "person", "pet" where "person"."first_name" = "pet"."name"
|
|
224
|
+
* ```
|
|
225
|
+
*
|
|
226
|
+
* Usage in a subquery:
|
|
227
|
+
*
|
|
228
|
+
* ```ts
|
|
229
|
+
* const persons = await db
|
|
230
|
+
* .selectFrom('person')
|
|
231
|
+
* .selectAll('person')
|
|
232
|
+
* .select((qb) => qb
|
|
233
|
+
* .selectFrom('pet')
|
|
234
|
+
* .select('name')
|
|
235
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
236
|
+
* .limit(1)
|
|
237
|
+
* .as('pet_name')
|
|
238
|
+
* )
|
|
239
|
+
* .execute()
|
|
240
|
+
* ```
|
|
241
|
+
*
|
|
242
|
+
* The generated SQL (PostgreSQL):
|
|
243
|
+
*
|
|
244
|
+
* ```sql
|
|
245
|
+
* select "person".*, (
|
|
246
|
+
* select "name"
|
|
247
|
+
* from "pet"
|
|
248
|
+
* where "pet"."owner_id" = "person"."id"
|
|
249
|
+
* limit $1
|
|
250
|
+
* ) as "pet_name"
|
|
251
|
+
* from "person"
|
|
252
|
+
*/
|
|
28
253
|
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
254
|
+
/**
|
|
255
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
256
|
+
*
|
|
257
|
+
* It's often necessary to wrap `or where` clauses in parentheses to control
|
|
258
|
+
* precendence. You can use the one argument version of the `where` method
|
|
259
|
+
* for that. See the examples.
|
|
260
|
+
*
|
|
261
|
+
* ### Examples
|
|
262
|
+
*
|
|
263
|
+
* ```ts
|
|
264
|
+
* const persons = await db
|
|
265
|
+
* .selectFrom('person')
|
|
266
|
+
* .selectAll()
|
|
267
|
+
* .where('id', '=', 1)
|
|
268
|
+
* .orWhere('id', '=', 2)
|
|
269
|
+
* .execute()
|
|
270
|
+
* ```
|
|
271
|
+
*
|
|
272
|
+
* The generated SQL (PostgreSQL):
|
|
273
|
+
*
|
|
274
|
+
* ```sql
|
|
275
|
+
* select * from "person" where "id" = 1 or "id" = 2
|
|
276
|
+
* ```
|
|
277
|
+
*
|
|
278
|
+
* Grouping with parentheses:
|
|
279
|
+
*
|
|
280
|
+
* ```ts
|
|
281
|
+
* const persons = await db
|
|
282
|
+
* .selectFrom('person')
|
|
283
|
+
* .selectAll()
|
|
284
|
+
* .where((qb) => qb
|
|
285
|
+
* .where('id', '=', 1)
|
|
286
|
+
* .orWhere('id', '=', 2)
|
|
287
|
+
* )
|
|
288
|
+
* .execute()
|
|
289
|
+
* ```
|
|
290
|
+
*
|
|
291
|
+
* The generated SQL (PostgreSQL):
|
|
292
|
+
*
|
|
293
|
+
* ```sql
|
|
294
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
295
|
+
* ```
|
|
296
|
+
*
|
|
297
|
+
* Even the first `where` can be an `orWhere`. This is useful
|
|
298
|
+
* if you are looping through a set of conditions:
|
|
299
|
+
*
|
|
300
|
+
* ```ts
|
|
301
|
+
* const persons = await db
|
|
302
|
+
* .selectFrom('person')
|
|
303
|
+
* .selectAll()
|
|
304
|
+
* .where((qb) => qb
|
|
305
|
+
* .orWhere('id', '=', 1)
|
|
306
|
+
* .orWhere('id', '=', 2)
|
|
307
|
+
* )
|
|
308
|
+
* .execute()
|
|
309
|
+
* ```
|
|
310
|
+
*
|
|
311
|
+
* The generated SQL (PostgreSQL):
|
|
312
|
+
*
|
|
313
|
+
* ```sql
|
|
314
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
315
|
+
* ```
|
|
316
|
+
*/
|
|
29
317
|
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): SelectQueryBuilder<DB, TB, O>;
|
|
30
318
|
orWhere(grouper: WhereGrouper<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
31
319
|
orWhere(raw: AnyRawBuilder): SelectQueryBuilder<DB, TB, O>;
|
|
320
|
+
/**
|
|
321
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link whereRef}.
|
|
322
|
+
*
|
|
323
|
+
* Also see {@link orWhere} and {@link where}.
|
|
324
|
+
*/
|
|
32
325
|
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
326
|
+
/**
|
|
327
|
+
* Adds a `where exists` clause to the query.
|
|
328
|
+
*
|
|
329
|
+
* You can either use a subquery or a raw instance.
|
|
330
|
+
*
|
|
331
|
+
* ### Examples
|
|
332
|
+
*
|
|
333
|
+
* The query below selets all persons that own a pet named Catto:
|
|
334
|
+
*
|
|
335
|
+
* ```ts
|
|
336
|
+
* const persons = await db
|
|
337
|
+
* .selectFrom('person')
|
|
338
|
+
* .selectAll()
|
|
339
|
+
* .whereExists((qb) => qb
|
|
340
|
+
* .selectFrom('pet')
|
|
341
|
+
* .select('pet.id')
|
|
342
|
+
* .whereRef('person.id', '=', 'pet.owner_id')
|
|
343
|
+
* .where('pet.name', '=', 'Catto')
|
|
344
|
+
* )
|
|
345
|
+
* .execute()
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* The generated SQL (PostgreSQL):
|
|
349
|
+
*
|
|
350
|
+
* ```sql
|
|
351
|
+
* select * from "person"
|
|
352
|
+
* where exists (
|
|
353
|
+
* select "pet"."id"
|
|
354
|
+
* from "pet"
|
|
355
|
+
* where "person"."id" = "pet"."owner_id"
|
|
356
|
+
* and "pet"."name" = $1
|
|
357
|
+
* )
|
|
358
|
+
* ```
|
|
359
|
+
*
|
|
360
|
+
* The same query as in the previous example but with using raw:
|
|
361
|
+
*
|
|
362
|
+
* ```ts
|
|
363
|
+
* db.selectFrom('person')
|
|
364
|
+
* .selectAll()
|
|
365
|
+
* .whereExists(
|
|
366
|
+
* db.raw(
|
|
367
|
+
* '(select pet.id from pet where person.id = pet.owner_id and pet.name = ?)',
|
|
368
|
+
* ['Catto']
|
|
369
|
+
* )
|
|
370
|
+
* )
|
|
371
|
+
* ```
|
|
372
|
+
*
|
|
373
|
+
* The generated SQL (PostgreSQL):
|
|
374
|
+
*
|
|
375
|
+
* ```sql
|
|
376
|
+
* select * from "person"
|
|
377
|
+
* where exists (
|
|
378
|
+
* select pet.id
|
|
379
|
+
* from pet
|
|
380
|
+
* where person.id = pet.owner_id
|
|
381
|
+
* and pet.name = $1
|
|
382
|
+
* )
|
|
383
|
+
* ```
|
|
384
|
+
*/
|
|
33
385
|
whereExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
386
|
+
/**
|
|
387
|
+
* Just like {@link whereExists} but creates a `not exists` clause.
|
|
388
|
+
*/
|
|
34
389
|
whereNotExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
390
|
+
/**
|
|
391
|
+
* Just like {@link whereExists} but creates a `or exists` clause.
|
|
392
|
+
*/
|
|
35
393
|
orWhereExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
394
|
+
/**
|
|
395
|
+
* Just like {@link whereExists} but creates a `or not exists` clause.
|
|
396
|
+
*/
|
|
36
397
|
orWhereNotExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
398
|
+
/**
|
|
399
|
+
* Just like {@link WhereInterface.where | where} but adds a `having` statement
|
|
400
|
+
* instead of a `where` statement.
|
|
401
|
+
*/
|
|
37
402
|
having<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): SelectQueryBuilder<DB, TB, O>;
|
|
38
403
|
having(grouper: HavingGrouper<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
39
404
|
having(raw: AnyRawBuilder): SelectQueryBuilder<DB, TB, O>;
|
|
405
|
+
/**
|
|
406
|
+
* Just like {@link WhereInterface.whereRef | whereRef} but adds a `having` statement
|
|
407
|
+
* instead of a `where` statement.
|
|
408
|
+
*/
|
|
40
409
|
havingRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
410
|
+
/**
|
|
411
|
+
* Just like {@link WhereInterface.orWhere | orWhere} but adds a `having` statement
|
|
412
|
+
* instead of a `where` statement.
|
|
413
|
+
*/
|
|
41
414
|
orHaving<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): SelectQueryBuilder<DB, TB, O>;
|
|
42
415
|
orHaving(grouper: HavingGrouper<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
43
416
|
orHaving(raw: AnyRawBuilder): SelectQueryBuilder<DB, TB, O>;
|
|
417
|
+
/**
|
|
418
|
+
* Just like {@link WhereInterface.orWhereRef | orWhereRef} but adds a `having` statement
|
|
419
|
+
* instead of a `where` statement.
|
|
420
|
+
*/
|
|
44
421
|
orHavingRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
422
|
+
/**
|
|
423
|
+
* Just like {@link WhereInterface.whereExists | whereExists} but adds a `having` statement
|
|
424
|
+
* instead of a `where` statement.
|
|
425
|
+
*/
|
|
45
426
|
havingExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
427
|
+
/**
|
|
428
|
+
* Just like {@link WhereInterface.whereNotExists | whereNotExists} but adds a `having` statement
|
|
429
|
+
* instead of a `where` statement.
|
|
430
|
+
*/
|
|
46
431
|
havingNotExist(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
432
|
+
/**
|
|
433
|
+
* Just like {@link WhereInterface.orWhereExists | orWhereExists} but adds a `having` statement
|
|
434
|
+
* instead of a `where` statement.
|
|
435
|
+
*/
|
|
47
436
|
orHavingExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
437
|
+
/**
|
|
438
|
+
* Just like {@link WhereInterface.orWhereNotExists | orWhereNotExists} but adds a `having` statement
|
|
439
|
+
* instead of a `where` statement.
|
|
440
|
+
*/
|
|
48
441
|
orHavingNotExists(arg: ExistsExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
49
442
|
/**
|
|
50
443
|
* Adds a select clause to the query.
|
|
@@ -339,12 +732,130 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
339
732
|
selectAll<T extends TB>(table: ReadonlyArray<T>): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
340
733
|
selectAll<T extends TB>(table: T): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
341
734
|
selectAll<T extends TB>(): SelectAllQueryBuilder<DB, TB, O, T>;
|
|
735
|
+
/**
|
|
736
|
+
* Joins another table to the query using an inner join.
|
|
737
|
+
*
|
|
738
|
+
* ### Examples
|
|
739
|
+
*
|
|
740
|
+
* Simple usage by providing a table name and two columns to join:
|
|
741
|
+
*
|
|
742
|
+
* ```ts
|
|
743
|
+
* const result = await db
|
|
744
|
+
* .selectFrom('person')
|
|
745
|
+
* .innerJoin('pet', 'pet.owner_id', 'person.id')
|
|
746
|
+
* // `select` needs to come after the call to `innerJoin` so
|
|
747
|
+
* // that you can select from the joined table.
|
|
748
|
+
* .select('person.id', 'pet.name')
|
|
749
|
+
* .execute()
|
|
750
|
+
*
|
|
751
|
+
* result[0].id
|
|
752
|
+
* result[0].name
|
|
753
|
+
* ```
|
|
754
|
+
*
|
|
755
|
+
* The generated SQL (PostgreSQL):
|
|
756
|
+
*
|
|
757
|
+
* ```sql
|
|
758
|
+
* select "person"."id", "pet"."name"
|
|
759
|
+
* from "person"
|
|
760
|
+
* inner join "pet"
|
|
761
|
+
* on "pet"."owner_id" = "person"."id"
|
|
762
|
+
* ```
|
|
763
|
+
*
|
|
764
|
+
* You can give an alias for the joined table like this:
|
|
765
|
+
*
|
|
766
|
+
* ```ts
|
|
767
|
+
* await db.selectFrom('person')
|
|
768
|
+
* .innerJoin('pet as p', 'p.owner_id', 'person.id')
|
|
769
|
+
* .where('p.name', '=', 'Doggo')
|
|
770
|
+
* .selectAll()
|
|
771
|
+
* .execute()
|
|
772
|
+
* ```
|
|
773
|
+
*
|
|
774
|
+
* The generated SQL (PostgreSQL):
|
|
775
|
+
*
|
|
776
|
+
* ```sql
|
|
777
|
+
* select *
|
|
778
|
+
* from "person"
|
|
779
|
+
* inner join "pet" as "p"
|
|
780
|
+
* on "p"."owner_id" = "person"."id"
|
|
781
|
+
* where "p".name" = $1
|
|
782
|
+
* ```
|
|
783
|
+
*
|
|
784
|
+
* You can provide a function as the second argument to get a join
|
|
785
|
+
* builder for creating more complex joins. The join builder has a
|
|
786
|
+
* bunch of `on*` methods for building the `on` clause of the join.
|
|
787
|
+
* There's basically an equivalent for every `where` method
|
|
788
|
+
* (`on`, `onRef`, `onExists` etc.). You can do all the same things
|
|
789
|
+
* with the `on` method that you can with the corresponding `where`
|
|
790
|
+
* method. See the `where` method documentation for more examples.
|
|
791
|
+
*
|
|
792
|
+
* ```ts
|
|
793
|
+
* await db.selectFrom('person')
|
|
794
|
+
* .innerJoin(
|
|
795
|
+
* 'pet',
|
|
796
|
+
* (join) => join
|
|
797
|
+
* .onRef('pet.owner_id', '=', 'person.id')
|
|
798
|
+
* .on('pet.name', '=', 'Doggo')
|
|
799
|
+
* )
|
|
800
|
+
* .selectAll()
|
|
801
|
+
* .execute()
|
|
802
|
+
* ```
|
|
803
|
+
*
|
|
804
|
+
* The generated SQL (PostgreSQL):
|
|
805
|
+
*
|
|
806
|
+
* ```sql
|
|
807
|
+
* select *
|
|
808
|
+
* from "person"
|
|
809
|
+
* inner join "pet"
|
|
810
|
+
* on "pet"."owner_id" = "person"."id"
|
|
811
|
+
* and "pet"."name" = $1
|
|
812
|
+
* ```
|
|
813
|
+
*
|
|
814
|
+
* You can join a subquery by providing a function as the first
|
|
815
|
+
* argument:
|
|
816
|
+
*
|
|
817
|
+
* ```ts
|
|
818
|
+
* await db.selectFrom('person')
|
|
819
|
+
* .innerJoin(
|
|
820
|
+
* (qb) => qb.selectFrom('pet')
|
|
821
|
+
* .select(['owner_id', 'name'])
|
|
822
|
+
* .where('name', '=', 'Doggo')
|
|
823
|
+
* .as('doggos'),
|
|
824
|
+
* 'doggos.owner_id',
|
|
825
|
+
* 'person.id',
|
|
826
|
+
* )
|
|
827
|
+
* .selectAll()
|
|
828
|
+
* .execute()
|
|
829
|
+
* ```
|
|
830
|
+
*
|
|
831
|
+
* The generated SQL (PostgreSQL):
|
|
832
|
+
*
|
|
833
|
+
* ```sql
|
|
834
|
+
* select *
|
|
835
|
+
* from "person"
|
|
836
|
+
* inner join (
|
|
837
|
+
* select "owner_id", "name"
|
|
838
|
+
* from "pet"
|
|
839
|
+
* where "name" = $1
|
|
840
|
+
* ) as "doggos"
|
|
841
|
+
* on "doggos"."owner_id" = "person"."id"
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
342
844
|
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): SelectQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
343
845
|
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): SelectQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
846
|
+
/**
|
|
847
|
+
* Just like {@link innerJoin} but adds a left join nstead of an inner join.
|
|
848
|
+
*/
|
|
344
849
|
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): SelectQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
345
850
|
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): SelectQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
851
|
+
/**
|
|
852
|
+
* Just like {@link innerJoin} but adds a right join instead of an inner join.
|
|
853
|
+
*/
|
|
346
854
|
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): SelectQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
347
855
|
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): SelectQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
856
|
+
/**
|
|
857
|
+
* Just like {@link innerJoin} but adds a full join instead of an inner join.
|
|
858
|
+
*/
|
|
348
859
|
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): SelectQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
349
860
|
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): SelectQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
350
861
|
/**
|
|
@@ -529,8 +1040,8 @@ export declare class SelectQueryBuilder<DB, TB extends keyof DB, O> implements W
|
|
|
529
1040
|
* group by "first_name"
|
|
530
1041
|
* ```
|
|
531
1042
|
*/
|
|
532
|
-
groupBy(
|
|
533
|
-
groupBy(
|
|
1043
|
+
groupBy(groupBy: ReadonlyArray<ReferenceExpression<DB, TB>>): SelectQueryBuilder<DB, TB, O>;
|
|
1044
|
+
groupBy(groupBy: ReferenceExpression<DB, TB>): SelectQueryBuilder<DB, TB, O>;
|
|
534
1045
|
/**
|
|
535
1046
|
* Adds a limit clause to the query.
|
|
536
1047
|
*
|
|
@@ -324,10 +324,10 @@ export class SelectQueryBuilder {
|
|
|
324
324
|
queryNode: SelectQueryNode.cloneWithOrderByItem(this.#props.queryNode, parseOrderBy(this.#props.parseContext, orderBy, direction)),
|
|
325
325
|
});
|
|
326
326
|
}
|
|
327
|
-
groupBy(
|
|
327
|
+
groupBy(groupBy) {
|
|
328
328
|
return new SelectQueryBuilder({
|
|
329
329
|
...this.#props,
|
|
330
|
-
queryNode: SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, parseGroupBy(this.#props.parseContext,
|
|
330
|
+
queryNode: SelectQueryNode.cloneWithGroupByItems(this.#props.queryNode, parseGroupBy(this.#props.parseContext, groupBy)),
|
|
331
331
|
});
|
|
332
332
|
}
|
|
333
333
|
/**
|