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
|
@@ -20,28 +20,573 @@ import { DeleteQueryNode } from '../operation-node/delete-query-node.js';
|
|
|
20
20
|
export declare class DeleteQueryBuilder<DB, TB extends keyof DB, O> implements WhereInterface<DB, TB>, JoinInterface<DB, TB>, ReturningInterface<DB, TB, O>, OperationNodeSource, Compilable {
|
|
21
21
|
#private;
|
|
22
22
|
constructor(props: DeleteQueryBuilderProps);
|
|
23
|
+
/**
|
|
24
|
+
* Adds a `where` clause to the query.
|
|
25
|
+
*
|
|
26
|
+
* Also see {@link orWhere}, {@link whereExists} and {@link whereRef}.
|
|
27
|
+
*
|
|
28
|
+
* ### Examples
|
|
29
|
+
*
|
|
30
|
+
* Find a row by column value:
|
|
31
|
+
*
|
|
32
|
+
* ```ts
|
|
33
|
+
* const person = await db
|
|
34
|
+
* .selectFrom('person')
|
|
35
|
+
* .selectAll()
|
|
36
|
+
* .where('id', '=', 100)
|
|
37
|
+
* .executeTakeFirst()
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* The generated SQL (PostgreSQL):
|
|
41
|
+
*
|
|
42
|
+
* ```sql
|
|
43
|
+
* select * from "person" where "id" = $1
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* Operator can be any supported operator or if the typings don't support it
|
|
47
|
+
* you can always use `db.raw('your operator')`.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* const persons = await db
|
|
51
|
+
* .selectFrom('person')
|
|
52
|
+
* .selectAll()
|
|
53
|
+
* .where('id', '>', 100)
|
|
54
|
+
* .execute()
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* The generated SQL (PostgreSQL):
|
|
58
|
+
*
|
|
59
|
+
* ```sql
|
|
60
|
+
* select * from "person" where "id" > $1
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* The `where` methods don't change the type of the query. You can add
|
|
64
|
+
* conditional `where`s easily by doing something like this:
|
|
65
|
+
*
|
|
66
|
+
* ```ts
|
|
67
|
+
* let query = db
|
|
68
|
+
* .selectFrom('person')
|
|
69
|
+
* .selectAll()
|
|
70
|
+
*
|
|
71
|
+
* if (firstName) {
|
|
72
|
+
* query = query.where('first_name', '=', firstName)
|
|
73
|
+
* }
|
|
74
|
+
*
|
|
75
|
+
* const persons = await query.execute()
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* This is true for basically all methods execpt the `select` and
|
|
79
|
+
* `returning` methods, which DO change the return type of the
|
|
80
|
+
* query.
|
|
81
|
+
*
|
|
82
|
+
* Both the first and third argument can also be subqueries.
|
|
83
|
+
* A subquery is defined by passing a function and calling
|
|
84
|
+
* the `selectFrom` method of the object passed into the
|
|
85
|
+
* function:
|
|
86
|
+
*
|
|
87
|
+
* ```ts
|
|
88
|
+
* const persons = await db
|
|
89
|
+
* .selectFrom('person')
|
|
90
|
+
* .selectAll()
|
|
91
|
+
* .where(
|
|
92
|
+
* (qb) => qb.selectFrom('pet')
|
|
93
|
+
* .select('pet.name')
|
|
94
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
95
|
+
* .limit(1),
|
|
96
|
+
* '=',
|
|
97
|
+
* 'Fluffy'
|
|
98
|
+
* )
|
|
99
|
+
* .execute()
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* The generated SQL (PostgreSQL):
|
|
103
|
+
*
|
|
104
|
+
* ```sql
|
|
105
|
+
* select *
|
|
106
|
+
* from "person"
|
|
107
|
+
* where (
|
|
108
|
+
* select "pet"."name"
|
|
109
|
+
* from "pet"
|
|
110
|
+
* where "pet"."owner_id" = "person"."id"
|
|
111
|
+
* limit $1
|
|
112
|
+
* ) = $2
|
|
113
|
+
* ```
|
|
114
|
+
*
|
|
115
|
+
* A `where in` query can be built by using the `in` operator and an array
|
|
116
|
+
* of values. The values in the array can also be subqueries or raw
|
|
117
|
+
* instances.
|
|
118
|
+
*
|
|
119
|
+
* ```ts
|
|
120
|
+
* const persons = await db
|
|
121
|
+
* .selectFrom('person')
|
|
122
|
+
* .selectAll()
|
|
123
|
+
* .where('person.id', 'in', [100, 200, 300])
|
|
124
|
+
* .execute()
|
|
125
|
+
* ```
|
|
126
|
+
*
|
|
127
|
+
* The generated SQL (PostgreSQL):
|
|
128
|
+
*
|
|
129
|
+
* ```sql
|
|
130
|
+
* select * from "person" where "id" in ($1, $2, $3)
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* If everything else fails, you can always pass {@link Kysely.raw | raw}
|
|
134
|
+
* as any of the arguments, including the operator:
|
|
135
|
+
*
|
|
136
|
+
* ```ts
|
|
137
|
+
* const persons = await db
|
|
138
|
+
* .selectFrom('person')
|
|
139
|
+
* .selectAll()
|
|
140
|
+
* .where(
|
|
141
|
+
* db.raw('coalesce(first_name, last_name)'),
|
|
142
|
+
* 'like',
|
|
143
|
+
* '%' + name + '%',
|
|
144
|
+
* )
|
|
145
|
+
* .execute()
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* The generated SQL (PostgreSQL):
|
|
149
|
+
*
|
|
150
|
+
* ```sql
|
|
151
|
+
* select * from "person"
|
|
152
|
+
* where coalesce(first_name, last_name) like $1
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* If you only pass one function argument to this method, it can be
|
|
156
|
+
* used to create parentheses around other where statements:
|
|
157
|
+
*
|
|
158
|
+
* ```ts
|
|
159
|
+
* const persons = await db
|
|
160
|
+
* .selectFrom('person')
|
|
161
|
+
* .selectAll()
|
|
162
|
+
* .where((qb) => qb
|
|
163
|
+
* .where('id', '=', 1)
|
|
164
|
+
* .orWhere('id', '=', 2)
|
|
165
|
+
* )
|
|
166
|
+
* .execute()
|
|
167
|
+
* ```
|
|
168
|
+
*
|
|
169
|
+
* The generated SQL (PostgreSQL):
|
|
170
|
+
*
|
|
171
|
+
* ```sql
|
|
172
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
173
|
+
* ```
|
|
174
|
+
*
|
|
175
|
+
* In all examples above the columns were known at compile time
|
|
176
|
+
* (except for the `raw` expressions). By default kysely only allows
|
|
177
|
+
* you to refer to columns that exist in the database **and** can be
|
|
178
|
+
* referred to in the current query and context.
|
|
179
|
+
*
|
|
180
|
+
* Sometimes you may want to refer to columns that come from the user
|
|
181
|
+
* input and thus are not available at compile time.
|
|
182
|
+
*
|
|
183
|
+
* You have two options, `db.raw` or `db.dynamic`. The example below
|
|
184
|
+
* uses both:
|
|
185
|
+
*
|
|
186
|
+
* ```ts
|
|
187
|
+
* const { ref } = db.dynamic
|
|
188
|
+
*
|
|
189
|
+
* const persons = await db
|
|
190
|
+
* .selectFrom('person')
|
|
191
|
+
* .selectAll()
|
|
192
|
+
* .where(ref(columnFromUserInput), '=', 1)
|
|
193
|
+
* .orWhere(db.raw('??', [columnFromUserInput]), '=', 2)
|
|
194
|
+
* .execute()
|
|
195
|
+
* ```
|
|
196
|
+
*/
|
|
23
197
|
where<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): DeleteQueryBuilder<DB, TB, O>;
|
|
24
198
|
where(grouper: WhereGrouper<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
25
199
|
where(raw: AnyRawBuilder): DeleteQueryBuilder<DB, TB, O>;
|
|
200
|
+
/**
|
|
201
|
+
* Adds a `where` clause where both sides of the operator are references
|
|
202
|
+
* to columns.
|
|
203
|
+
*
|
|
204
|
+
* The normal `where` method treats the right hand side argument as a
|
|
205
|
+
* value by default. `whereRef` treats it as a column reference. This method is
|
|
206
|
+
* expecially useful with joins and correclated subqueries.
|
|
207
|
+
*
|
|
208
|
+
* ### Examples
|
|
209
|
+
*
|
|
210
|
+
* Usage with a join:
|
|
211
|
+
*
|
|
212
|
+
* ```ts
|
|
213
|
+
* db.selectFrom(['person', 'pet'])
|
|
214
|
+
* .selectAll()
|
|
215
|
+
* .whereRef('person.first_name', '=', 'pet.name')
|
|
216
|
+
* ```
|
|
217
|
+
*
|
|
218
|
+
* The generated SQL (PostgreSQL):
|
|
219
|
+
*
|
|
220
|
+
* ```sql
|
|
221
|
+
* select * from "person", "pet" where "person"."first_name" = "pet"."name"
|
|
222
|
+
* ```
|
|
223
|
+
*
|
|
224
|
+
* Usage in a subquery:
|
|
225
|
+
*
|
|
226
|
+
* ```ts
|
|
227
|
+
* const persons = await db
|
|
228
|
+
* .selectFrom('person')
|
|
229
|
+
* .selectAll('person')
|
|
230
|
+
* .select((qb) => qb
|
|
231
|
+
* .selectFrom('pet')
|
|
232
|
+
* .select('name')
|
|
233
|
+
* .whereRef('pet.owner_id', '=', 'person.id')
|
|
234
|
+
* .limit(1)
|
|
235
|
+
* .as('pet_name')
|
|
236
|
+
* )
|
|
237
|
+
* .execute()
|
|
238
|
+
* ```
|
|
239
|
+
*
|
|
240
|
+
* The generated SQL (PostgreSQL):
|
|
241
|
+
*
|
|
242
|
+
* ```sql
|
|
243
|
+
* select "person".*, (
|
|
244
|
+
* select "name"
|
|
245
|
+
* from "pet"
|
|
246
|
+
* where "pet"."owner_id" = "person"."id"
|
|
247
|
+
* limit $1
|
|
248
|
+
* ) as "pet_name"
|
|
249
|
+
* from "person"
|
|
250
|
+
*/
|
|
26
251
|
whereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
252
|
+
/**
|
|
253
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link where}.
|
|
254
|
+
*
|
|
255
|
+
* It's often necessary to wrap `or where` clauses in parentheses to control
|
|
256
|
+
* precendence. You can use the one argument version of the `where` method
|
|
257
|
+
* for that. See the examples.
|
|
258
|
+
*
|
|
259
|
+
* ### Examples
|
|
260
|
+
*
|
|
261
|
+
* ```ts
|
|
262
|
+
* const persons = await db
|
|
263
|
+
* .selectFrom('person')
|
|
264
|
+
* .selectAll()
|
|
265
|
+
* .where('id', '=', 1)
|
|
266
|
+
* .orWhere('id', '=', 2)
|
|
267
|
+
* .execute()
|
|
268
|
+
* ```
|
|
269
|
+
*
|
|
270
|
+
* The generated SQL (PostgreSQL):
|
|
271
|
+
*
|
|
272
|
+
* ```sql
|
|
273
|
+
* select * from "person" where "id" = 1 or "id" = 2
|
|
274
|
+
* ```
|
|
275
|
+
*
|
|
276
|
+
* Grouping with parentheses:
|
|
277
|
+
*
|
|
278
|
+
* ```ts
|
|
279
|
+
* const persons = await db
|
|
280
|
+
* .selectFrom('person')
|
|
281
|
+
* .selectAll()
|
|
282
|
+
* .where((qb) => qb
|
|
283
|
+
* .where('id', '=', 1)
|
|
284
|
+
* .orWhere('id', '=', 2)
|
|
285
|
+
* )
|
|
286
|
+
* .execute()
|
|
287
|
+
* ```
|
|
288
|
+
*
|
|
289
|
+
* The generated SQL (PostgreSQL):
|
|
290
|
+
*
|
|
291
|
+
* ```sql
|
|
292
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
293
|
+
* ```
|
|
294
|
+
*
|
|
295
|
+
* Even the first `where` can be an `orWhere`. This is useful
|
|
296
|
+
* if you are looping through a set of conditions:
|
|
297
|
+
*
|
|
298
|
+
* ```ts
|
|
299
|
+
* const persons = await db
|
|
300
|
+
* .selectFrom('person')
|
|
301
|
+
* .selectAll()
|
|
302
|
+
* .where((qb) => qb
|
|
303
|
+
* .orWhere('id', '=', 1)
|
|
304
|
+
* .orWhere('id', '=', 2)
|
|
305
|
+
* )
|
|
306
|
+
* .execute()
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* The generated SQL (PostgreSQL):
|
|
310
|
+
*
|
|
311
|
+
* ```sql
|
|
312
|
+
* select * from "person" (where "id" = 1 or "id" = 2)
|
|
313
|
+
* ```
|
|
314
|
+
*/
|
|
27
315
|
orWhere<RE extends ReferenceExpression<DB, TB>>(lhs: RE, op: FilterOperator, rhs: FilterValueExpressionOrList<DB, TB, RE>): DeleteQueryBuilder<DB, TB, O>;
|
|
28
316
|
orWhere(grouper: WhereGrouper<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
29
317
|
orWhere(raw: AnyRawBuilder): DeleteQueryBuilder<DB, TB, O>;
|
|
318
|
+
/**
|
|
319
|
+
* Adds an `or where` clause to the query. Otherwise works just like {@link whereRef}.
|
|
320
|
+
*
|
|
321
|
+
* Also see {@link orWhere} and {@link where}.
|
|
322
|
+
*/
|
|
30
323
|
orWhereRef(lhs: ReferenceExpression<DB, TB>, op: FilterOperator, rhs: ReferenceExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
324
|
+
/**
|
|
325
|
+
* Adds a `where exists` clause to the query.
|
|
326
|
+
*
|
|
327
|
+
* You can either use a subquery or a raw instance.
|
|
328
|
+
*
|
|
329
|
+
* ### Examples
|
|
330
|
+
*
|
|
331
|
+
* The query below selets all persons that own a pet named Catto:
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* const persons = await db
|
|
335
|
+
* .selectFrom('person')
|
|
336
|
+
* .selectAll()
|
|
337
|
+
* .whereExists((qb) => qb
|
|
338
|
+
* .selectFrom('pet')
|
|
339
|
+
* .select('pet.id')
|
|
340
|
+
* .whereRef('person.id', '=', 'pet.owner_id')
|
|
341
|
+
* .where('pet.name', '=', 'Catto')
|
|
342
|
+
* )
|
|
343
|
+
* .execute()
|
|
344
|
+
* ```
|
|
345
|
+
*
|
|
346
|
+
* The generated SQL (PostgreSQL):
|
|
347
|
+
*
|
|
348
|
+
* ```sql
|
|
349
|
+
* select * from "person"
|
|
350
|
+
* where exists (
|
|
351
|
+
* select "pet"."id"
|
|
352
|
+
* from "pet"
|
|
353
|
+
* where "person"."id" = "pet"."owner_id"
|
|
354
|
+
* and "pet"."name" = $1
|
|
355
|
+
* )
|
|
356
|
+
* ```
|
|
357
|
+
*
|
|
358
|
+
* The same query as in the previous example but with using raw:
|
|
359
|
+
*
|
|
360
|
+
* ```ts
|
|
361
|
+
* db.selectFrom('person')
|
|
362
|
+
* .selectAll()
|
|
363
|
+
* .whereExists(
|
|
364
|
+
* db.raw(
|
|
365
|
+
* '(select pet.id from pet where person.id = pet.owner_id and pet.name = ?)',
|
|
366
|
+
* ['Catto']
|
|
367
|
+
* )
|
|
368
|
+
* )
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* The generated SQL (PostgreSQL):
|
|
372
|
+
*
|
|
373
|
+
* ```sql
|
|
374
|
+
* select * from "person"
|
|
375
|
+
* where exists (
|
|
376
|
+
* select pet.id
|
|
377
|
+
* from pet
|
|
378
|
+
* where person.id = pet.owner_id
|
|
379
|
+
* and pet.name = $1
|
|
380
|
+
* )
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
31
383
|
whereExists(arg: ExistsExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
384
|
+
/**
|
|
385
|
+
* Just like {@link whereExists} but creates a `not exists` clause.
|
|
386
|
+
*/
|
|
32
387
|
whereNotExists(arg: ExistsExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
388
|
+
/**
|
|
389
|
+
* Just like {@link whereExists} but creates a `or exists` clause.
|
|
390
|
+
*/
|
|
33
391
|
orWhereExists(arg: ExistsExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
392
|
+
/**
|
|
393
|
+
* Just like {@link whereExists} but creates a `or not exists` clause.
|
|
394
|
+
*/
|
|
34
395
|
orWhereNotExists(arg: ExistsExpression<DB, TB>): DeleteQueryBuilder<DB, TB, O>;
|
|
396
|
+
/**
|
|
397
|
+
* Joins another table to the query using an inner join.
|
|
398
|
+
*
|
|
399
|
+
* ### Examples
|
|
400
|
+
*
|
|
401
|
+
* Simple usage by providing a table name and two columns to join:
|
|
402
|
+
*
|
|
403
|
+
* ```ts
|
|
404
|
+
* const result = await db
|
|
405
|
+
* .selectFrom('person')
|
|
406
|
+
* .innerJoin('pet', 'pet.owner_id', 'person.id')
|
|
407
|
+
* // `select` needs to come after the call to `innerJoin` so
|
|
408
|
+
* // that you can select from the joined table.
|
|
409
|
+
* .select('person.id', 'pet.name')
|
|
410
|
+
* .execute()
|
|
411
|
+
*
|
|
412
|
+
* result[0].id
|
|
413
|
+
* result[0].name
|
|
414
|
+
* ```
|
|
415
|
+
*
|
|
416
|
+
* The generated SQL (PostgreSQL):
|
|
417
|
+
*
|
|
418
|
+
* ```sql
|
|
419
|
+
* select "person"."id", "pet"."name"
|
|
420
|
+
* from "person"
|
|
421
|
+
* inner join "pet"
|
|
422
|
+
* on "pet"."owner_id" = "person"."id"
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* You can give an alias for the joined table like this:
|
|
426
|
+
*
|
|
427
|
+
* ```ts
|
|
428
|
+
* await db.selectFrom('person')
|
|
429
|
+
* .innerJoin('pet as p', 'p.owner_id', 'person.id')
|
|
430
|
+
* .where('p.name', '=', 'Doggo')
|
|
431
|
+
* .selectAll()
|
|
432
|
+
* .execute()
|
|
433
|
+
* ```
|
|
434
|
+
*
|
|
435
|
+
* The generated SQL (PostgreSQL):
|
|
436
|
+
*
|
|
437
|
+
* ```sql
|
|
438
|
+
* select *
|
|
439
|
+
* from "person"
|
|
440
|
+
* inner join "pet" as "p"
|
|
441
|
+
* on "p"."owner_id" = "person"."id"
|
|
442
|
+
* where "p".name" = $1
|
|
443
|
+
* ```
|
|
444
|
+
*
|
|
445
|
+
* You can provide a function as the second argument to get a join
|
|
446
|
+
* builder for creating more complex joins. The join builder has a
|
|
447
|
+
* bunch of `on*` methods for building the `on` clause of the join.
|
|
448
|
+
* There's basically an equivalent for every `where` method
|
|
449
|
+
* (`on`, `onRef`, `onExists` etc.). You can do all the same things
|
|
450
|
+
* with the `on` method that you can with the corresponding `where`
|
|
451
|
+
* method. See the `where` method documentation for more examples.
|
|
452
|
+
*
|
|
453
|
+
* ```ts
|
|
454
|
+
* await db.selectFrom('person')
|
|
455
|
+
* .innerJoin(
|
|
456
|
+
* 'pet',
|
|
457
|
+
* (join) => join
|
|
458
|
+
* .onRef('pet.owner_id', '=', 'person.id')
|
|
459
|
+
* .on('pet.name', '=', 'Doggo')
|
|
460
|
+
* )
|
|
461
|
+
* .selectAll()
|
|
462
|
+
* .execute()
|
|
463
|
+
* ```
|
|
464
|
+
*
|
|
465
|
+
* The generated SQL (PostgreSQL):
|
|
466
|
+
*
|
|
467
|
+
* ```sql
|
|
468
|
+
* select *
|
|
469
|
+
* from "person"
|
|
470
|
+
* inner join "pet"
|
|
471
|
+
* on "pet"."owner_id" = "person"."id"
|
|
472
|
+
* and "pet"."name" = $1
|
|
473
|
+
* ```
|
|
474
|
+
*
|
|
475
|
+
* You can join a subquery by providing a function as the first
|
|
476
|
+
* argument:
|
|
477
|
+
*
|
|
478
|
+
* ```ts
|
|
479
|
+
* await db.selectFrom('person')
|
|
480
|
+
* .innerJoin(
|
|
481
|
+
* (qb) => qb.selectFrom('pet')
|
|
482
|
+
* .select(['owner_id', 'name'])
|
|
483
|
+
* .where('name', '=', 'Doggo')
|
|
484
|
+
* .as('doggos'),
|
|
485
|
+
* 'doggos.owner_id',
|
|
486
|
+
* 'person.id',
|
|
487
|
+
* )
|
|
488
|
+
* .selectAll()
|
|
489
|
+
* .execute()
|
|
490
|
+
* ```
|
|
491
|
+
*
|
|
492
|
+
* The generated SQL (PostgreSQL):
|
|
493
|
+
*
|
|
494
|
+
* ```sql
|
|
495
|
+
* select *
|
|
496
|
+
* from "person"
|
|
497
|
+
* inner join (
|
|
498
|
+
* select "owner_id", "name"
|
|
499
|
+
* from "pet"
|
|
500
|
+
* where "name" = $1
|
|
501
|
+
* ) as "doggos"
|
|
502
|
+
* on "doggos"."owner_id" = "person"."id"
|
|
503
|
+
* ```
|
|
504
|
+
*/
|
|
35
505
|
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): DeleteQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
36
506
|
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): DeleteQueryBuilder<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
507
|
+
/**
|
|
508
|
+
* Just like {@link innerJoin} but adds a left join nstead of an inner join.
|
|
509
|
+
*/
|
|
37
510
|
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): DeleteQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
38
511
|
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): DeleteQueryBuilder<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
512
|
+
/**
|
|
513
|
+
* Just like {@link innerJoin} but adds a right join instead of an inner join.
|
|
514
|
+
*/
|
|
39
515
|
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): DeleteQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
40
516
|
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): DeleteQueryBuilder<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
517
|
+
/**
|
|
518
|
+
* Just like {@link innerJoin} but adds a full join instead of an inner join.
|
|
519
|
+
*/
|
|
41
520
|
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): DeleteQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
42
521
|
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): DeleteQueryBuilder<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>, O>;
|
|
522
|
+
/**
|
|
523
|
+
* Allows you to return data from modified rows.
|
|
524
|
+
*
|
|
525
|
+
* On supported databases like PostgreSQL, this method can be chained to
|
|
526
|
+
* `insert`, `update` and `delete` queries to return data.
|
|
527
|
+
*
|
|
528
|
+
* Note that on SQLite you need to give aliases for the expressions to avoid
|
|
529
|
+
* [this bug](https://sqlite.org/forum/forumpost/033daf0b32) in SQLite.
|
|
530
|
+
* For example `.returning('id as id')`.
|
|
531
|
+
*
|
|
532
|
+
* Also see the {@link returningAll} method.
|
|
533
|
+
*
|
|
534
|
+
* ### Examples
|
|
535
|
+
*
|
|
536
|
+
* Return one column:
|
|
537
|
+
*
|
|
538
|
+
* ```ts
|
|
539
|
+
* const { id } = await db
|
|
540
|
+
* .insertInto('person')
|
|
541
|
+
* .values({
|
|
542
|
+
* id: db.generated,
|
|
543
|
+
* first_name: 'Jennifer',
|
|
544
|
+
* last_name: 'Aniston'
|
|
545
|
+
* })
|
|
546
|
+
* .returning('id')
|
|
547
|
+
* .executeTakeFirst()
|
|
548
|
+
* ```
|
|
549
|
+
*
|
|
550
|
+
* Return multiple columns:
|
|
551
|
+
*
|
|
552
|
+
* ```ts
|
|
553
|
+
* const { id, first_name } = await db
|
|
554
|
+
* .insertInto('person')
|
|
555
|
+
* .values({
|
|
556
|
+
* id: db.generated,
|
|
557
|
+
* first_name: 'Jennifer',
|
|
558
|
+
* last_name: 'Aniston'
|
|
559
|
+
* })
|
|
560
|
+
* .returning(['id', 'last_name'])
|
|
561
|
+
* .executeTakeFirst()
|
|
562
|
+
* ```
|
|
563
|
+
*
|
|
564
|
+
* Return arbitrary expressions:
|
|
565
|
+
*
|
|
566
|
+
* ```ts
|
|
567
|
+
* const { raw } = db
|
|
568
|
+
*
|
|
569
|
+
* const { id, full_name, first_pet_id } = await db
|
|
570
|
+
* .insertInto('person')
|
|
571
|
+
* .values({
|
|
572
|
+
* id: db.generated,
|
|
573
|
+
* first_name: 'Jennifer',
|
|
574
|
+
* last_name: 'Aniston'
|
|
575
|
+
* })
|
|
576
|
+
* .returning([
|
|
577
|
+
* 'id as id',
|
|
578
|
+
* raw<string>(`concat(first_name, ' ', last_name)`).as('full_name'),
|
|
579
|
+
* (qb) => qb.selectFrom('pets').select('pet.id').limit(1).as('first_pet_id')
|
|
580
|
+
* ])
|
|
581
|
+
* .executeTakeFirst()
|
|
582
|
+
* ```
|
|
583
|
+
*/
|
|
43
584
|
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): DeleteQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
44
585
|
returning<SE extends SelectExpression<DB, TB>>(selection: SE): DeleteQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
586
|
+
/**
|
|
587
|
+
* Adds a `returning *` to an insert/update/delete query on databases
|
|
588
|
+
* that support `returning` such as PostgreSQL.
|
|
589
|
+
*/
|
|
45
590
|
returningAll(): DeleteQueryBuilder<DB, TB, DB[TB]>;
|
|
46
591
|
/**
|
|
47
592
|
* Simply calls the given function passing `this` as the only argument.
|
|
@@ -209,8 +209,8 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
209
209
|
* statement. On MySQL you should use the {@link ignore} method to achieve
|
|
210
210
|
* similar results.
|
|
211
211
|
*
|
|
212
|
-
* Also see the {@link
|
|
213
|
-
*
|
|
212
|
+
* Also see the {@link onConflictUpdate} method if you want to perform an
|
|
213
|
+
* update in case of a conflict (upsert).
|
|
214
214
|
*
|
|
215
215
|
* ### Examples
|
|
216
216
|
*
|
|
@@ -303,8 +303,7 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
303
303
|
* like PostgreSQL and SQLite. On MySQL you should use the {@link onDuplicateKeyUpdate}
|
|
304
304
|
* method instead.
|
|
305
305
|
*
|
|
306
|
-
* Also see the {@link
|
|
307
|
-
* method.
|
|
306
|
+
* Also see the {@link onConflictDoNothing} method.
|
|
308
307
|
*
|
|
309
308
|
* ### Examples
|
|
310
309
|
*
|
|
@@ -376,8 +375,74 @@ export declare class InsertQueryBuilder<DB, TB extends keyof DB, O> implements R
|
|
|
376
375
|
* ```
|
|
377
376
|
*/
|
|
378
377
|
onDuplicateKeyUpdate(updates: MutationObject<DB, TB>): InsertQueryBuilder<DB, TB, O>;
|
|
378
|
+
/**
|
|
379
|
+
* Allows you to return data from modified rows.
|
|
380
|
+
*
|
|
381
|
+
* On supported databases like PostgreSQL, this method can be chained to
|
|
382
|
+
* `insert`, `update` and `delete` queries to return data.
|
|
383
|
+
*
|
|
384
|
+
* Note that on SQLite you need to give aliases for the expressions to avoid
|
|
385
|
+
* [this bug](https://sqlite.org/forum/forumpost/033daf0b32) in SQLite.
|
|
386
|
+
* For example `.returning('id as id')`.
|
|
387
|
+
*
|
|
388
|
+
* Also see the {@link returningAll} method.
|
|
389
|
+
*
|
|
390
|
+
* ### Examples
|
|
391
|
+
*
|
|
392
|
+
* Return one column:
|
|
393
|
+
*
|
|
394
|
+
* ```ts
|
|
395
|
+
* const { id } = await db
|
|
396
|
+
* .insertInto('person')
|
|
397
|
+
* .values({
|
|
398
|
+
* id: db.generated,
|
|
399
|
+
* first_name: 'Jennifer',
|
|
400
|
+
* last_name: 'Aniston'
|
|
401
|
+
* })
|
|
402
|
+
* .returning('id')
|
|
403
|
+
* .executeTakeFirst()
|
|
404
|
+
* ```
|
|
405
|
+
*
|
|
406
|
+
* Return multiple columns:
|
|
407
|
+
*
|
|
408
|
+
* ```ts
|
|
409
|
+
* const { id, first_name } = await db
|
|
410
|
+
* .insertInto('person')
|
|
411
|
+
* .values({
|
|
412
|
+
* id: db.generated,
|
|
413
|
+
* first_name: 'Jennifer',
|
|
414
|
+
* last_name: 'Aniston'
|
|
415
|
+
* })
|
|
416
|
+
* .returning(['id', 'last_name'])
|
|
417
|
+
* .executeTakeFirst()
|
|
418
|
+
* ```
|
|
419
|
+
*
|
|
420
|
+
* Return arbitrary expressions:
|
|
421
|
+
*
|
|
422
|
+
* ```ts
|
|
423
|
+
* const { raw } = db
|
|
424
|
+
*
|
|
425
|
+
* const { id, full_name, first_pet_id } = await db
|
|
426
|
+
* .insertInto('person')
|
|
427
|
+
* .values({
|
|
428
|
+
* id: db.generated,
|
|
429
|
+
* first_name: 'Jennifer',
|
|
430
|
+
* last_name: 'Aniston'
|
|
431
|
+
* })
|
|
432
|
+
* .returning([
|
|
433
|
+
* 'id as id',
|
|
434
|
+
* raw<string>(`concat(first_name, ' ', last_name)`).as('full_name'),
|
|
435
|
+
* (qb) => qb.selectFrom('pets').select('pet.id').limit(1).as('first_pet_id')
|
|
436
|
+
* ])
|
|
437
|
+
* .executeTakeFirst()
|
|
438
|
+
* ```
|
|
439
|
+
*/
|
|
379
440
|
returning<SE extends SelectExpression<DB, TB>>(selections: ReadonlyArray<SE>): InsertQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
380
441
|
returning<SE extends SelectExpression<DB, TB>>(selection: SE): InsertQueryBuilder<DB, TB, ReturningRow<DB, TB, O, SE>>;
|
|
442
|
+
/**
|
|
443
|
+
* Adds a `returning *` to an insert/update/delete query on databases
|
|
444
|
+
* that support `returning` such as PostgreSQL.
|
|
445
|
+
*/
|
|
381
446
|
returningAll(): InsertQueryBuilder<DB, TB, DB[TB]>;
|
|
382
447
|
/**
|
|
383
448
|
* Simply calls the given function passing `this` as the only argument.
|
|
@@ -113,20 +113,17 @@ export interface JoinInterface<DB, TB extends keyof DB> {
|
|
|
113
113
|
innerJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): JoinInterface<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
114
114
|
innerJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): JoinInterface<TableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
115
115
|
/**
|
|
116
|
-
* Just like {@link
|
|
117
|
-
* instead of an inner join.
|
|
116
|
+
* Just like {@link innerJoin} but adds a left join nstead of an inner join.
|
|
118
117
|
*/
|
|
119
118
|
leftJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): JoinInterface<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
120
119
|
leftJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): JoinInterface<LeftJoinTableExpressionDatabase<DB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
121
120
|
/**
|
|
122
|
-
* Just like {@link
|
|
123
|
-
* instead of an inner join.
|
|
121
|
+
* Just like {@link innerJoin} but adds a right join instead of an inner join.
|
|
124
122
|
*/
|
|
125
123
|
rightJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): JoinInterface<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
126
124
|
rightJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): JoinInterface<RightJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
127
125
|
/**
|
|
128
|
-
* Just like {@link
|
|
129
|
-
* instead of an inner join.
|
|
126
|
+
* Just like {@link innerJoin} but adds a full join instead of an inner join.
|
|
130
127
|
*/
|
|
131
128
|
fullJoin<TE extends TableExpression<DB, TB>, K1 extends JoinReferenceExpression<DB, TB, TE>, K2 extends JoinReferenceExpression<DB, TB, TE>>(table: TE, k1: K1, k2: K2): JoinInterface<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>>;
|
|
132
129
|
fullJoin<TE extends TableExpression<DB, TB>, FN extends JoinCallbackExpression<DB, TB, TE>>(table: TE, callback: FN): JoinInterface<FullJoinTableExpressionDatabase<DB, TB, TE>, TableExpressionTables<DB, TB, TE>>;
|