drizzle-orm 0.29.0 → 0.29.1-47754fb
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/aws-data-api/common/index.cjs +14 -1
- package/aws-data-api/common/index.cjs.map +1 -1
- package/aws-data-api/common/index.js +14 -1
- package/aws-data-api/common/index.js.map +1 -1
- package/mysql-core/db.cjs +134 -31
- package/mysql-core/db.cjs.map +1 -1
- package/mysql-core/db.d.cts +171 -1
- package/mysql-core/db.d.ts +171 -1
- package/mysql-core/db.js +134 -31
- package/mysql-core/db.js.map +1 -1
- package/mysql-core/query-builders/delete.cjs +29 -0
- package/mysql-core/query-builders/delete.cjs.map +1 -1
- package/mysql-core/query-builders/delete.d.cts +29 -0
- package/mysql-core/query-builders/delete.d.ts +29 -0
- package/mysql-core/query-builders/delete.js +29 -0
- package/mysql-core/query-builders/delete.js.map +1 -1
- package/mysql-core/query-builders/insert.cjs +26 -0
- package/mysql-core/query-builders/insert.cjs.map +1 -1
- package/mysql-core/query-builders/insert.d.cts +26 -0
- package/mysql-core/query-builders/insert.d.ts +26 -0
- package/mysql-core/query-builders/insert.js +26 -0
- package/mysql-core/query-builders/insert.js.map +1 -1
- package/mysql-core/query-builders/query.cjs +9 -1
- package/mysql-core/query-builders/query.cjs.map +1 -1
- package/mysql-core/query-builders/query.d.cts +1 -0
- package/mysql-core/query-builders/query.d.ts +1 -0
- package/mysql-core/query-builders/query.js +9 -1
- package/mysql-core/query-builders/query.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +381 -0
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.d.cts +604 -0
- package/mysql-core/query-builders/select.d.ts +604 -0
- package/mysql-core/query-builders/select.js +381 -0
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/query-builders/update.cjs +33 -0
- package/mysql-core/query-builders/update.cjs.map +1 -1
- package/mysql-core/query-builders/update.d.cts +33 -0
- package/mysql-core/query-builders/update.d.ts +33 -0
- package/mysql-core/query-builders/update.js +33 -0
- package/mysql-core/query-builders/update.js.map +1 -1
- package/mysql-core/view.cjs +2 -2
- package/mysql-core/view.cjs.map +1 -1
- package/mysql-core/view.d.cts +1 -1
- package/mysql-core/view.d.ts +1 -1
- package/mysql-core/view.js +2 -2
- package/mysql-core/view.js.map +1 -1
- package/mysql-proxy/migrator.cjs +2 -2
- package/mysql-proxy/migrator.cjs.map +1 -1
- package/mysql-proxy/migrator.js +2 -2
- package/mysql-proxy/migrator.js.map +1 -1
- package/package.json +25 -1
- package/pg-core/db.cjs +153 -34
- package/pg-core/db.cjs.map +1 -1
- package/pg-core/db.d.cts +211 -0
- package/pg-core/db.d.ts +211 -0
- package/pg-core/db.js +153 -34
- package/pg-core/db.js.map +1 -1
- package/pg-core/dialect.cjs +1 -1
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +1 -1
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/delete.cjs +29 -0
- package/pg-core/query-builders/delete.cjs.map +1 -1
- package/pg-core/query-builders/delete.d.cts +49 -0
- package/pg-core/query-builders/delete.d.ts +49 -0
- package/pg-core/query-builders/delete.js +29 -0
- package/pg-core/query-builders/delete.js.map +1 -1
- package/pg-core/query-builders/insert.cjs +51 -0
- package/pg-core/query-builders/insert.cjs.map +1 -1
- package/pg-core/query-builders/insert.d.cts +71 -0
- package/pg-core/query-builders/insert.d.ts +71 -0
- package/pg-core/query-builders/insert.js +51 -0
- package/pg-core/query-builders/insert.js.map +1 -1
- package/pg-core/query-builders/query.cjs +9 -2
- package/pg-core/query-builders/query.cjs.map +1 -1
- package/pg-core/query-builders/query.d.cts +1 -0
- package/pg-core/query-builders/query.d.ts +1 -0
- package/pg-core/query-builders/query.js +9 -2
- package/pg-core/query-builders/query.js.map +1 -1
- package/pg-core/query-builders/select.cjs +354 -48
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +555 -59
- package/pg-core/query-builders/select.d.ts +555 -59
- package/pg-core/query-builders/select.js +354 -48
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/update.cjs +33 -0
- package/pg-core/query-builders/update.cjs.map +1 -1
- package/pg-core/query-builders/update.d.cts +55 -0
- package/pg-core/query-builders/update.d.ts +55 -0
- package/pg-core/query-builders/update.js +33 -0
- package/pg-core/query-builders/update.js.map +1 -1
- package/pg-proxy/migrator.cjs +1 -1
- package/pg-proxy/migrator.cjs.map +1 -1
- package/pg-proxy/migrator.js +1 -1
- package/pg-proxy/migrator.js.map +1 -1
- package/sql/functions/aggregate.cjs +69 -0
- package/sql/functions/aggregate.cjs.map +1 -0
- package/sql/functions/aggregate.d.cts +104 -0
- package/sql/functions/aggregate.d.ts +104 -0
- package/sql/functions/aggregate.js +38 -0
- package/sql/functions/aggregate.js.map +1 -0
- package/sql/functions/index.cjs +23 -0
- package/sql/functions/index.cjs.map +1 -0
- package/sql/functions/index.d.cts +1 -0
- package/sql/functions/index.d.ts +1 -0
- package/sql/functions/index.js +2 -0
- package/sql/functions/index.js.map +1 -0
- package/sql/index.cjs +3 -1
- package/sql/index.cjs.map +1 -1
- package/sql/index.d.cts +1 -0
- package/sql/index.d.ts +1 -0
- package/sql/index.js +1 -0
- package/sql/index.js.map +1 -1
- package/sql/sql.cjs.map +1 -1
- package/sql/sql.js.map +1 -1
- package/sqlite-core/db.cjs +155 -36
- package/sqlite-core/db.cjs.map +1 -1
- package/sqlite-core/db.d.cts +187 -0
- package/sqlite-core/db.d.ts +187 -0
- package/sqlite-core/db.js +155 -36
- package/sqlite-core/db.js.map +1 -1
- package/sqlite-core/query-builders/delete.cjs +29 -0
- package/sqlite-core/query-builders/delete.cjs.map +1 -1
- package/sqlite-core/query-builders/delete.d.cts +49 -0
- package/sqlite-core/query-builders/delete.d.ts +49 -0
- package/sqlite-core/query-builders/delete.js +29 -0
- package/sqlite-core/query-builders/delete.js.map +1 -1
- package/sqlite-core/query-builders/insert.cjs +51 -0
- package/sqlite-core/query-builders/insert.cjs.map +1 -1
- package/sqlite-core/query-builders/insert.d.cts +71 -0
- package/sqlite-core/query-builders/insert.d.ts +71 -0
- package/sqlite-core/query-builders/insert.js +51 -0
- package/sqlite-core/query-builders/insert.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +291 -0
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +434 -0
- package/sqlite-core/query-builders/select.d.ts +434 -0
- package/sqlite-core/query-builders/select.js +291 -0
- package/sqlite-core/query-builders/select.js.map +1 -1
- package/sqlite-core/query-builders/select.types.cjs.map +1 -1
- package/sqlite-core/query-builders/update.cjs +33 -0
- package/sqlite-core/query-builders/update.cjs.map +1 -1
- package/sqlite-core/query-builders/update.d.cts +55 -0
- package/sqlite-core/query-builders/update.d.ts +55 -0
- package/sqlite-core/query-builders/update.js +33 -0
- package/sqlite-core/query-builders/update.js.map +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -146,32 +146,115 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
146
146
|
};
|
|
147
147
|
}
|
|
148
148
|
/**
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
* table, if
|
|
152
|
-
*
|
|
153
|
-
*
|
|
149
|
+
* Executes a `left join` operation by adding another table to the current query.
|
|
150
|
+
*
|
|
151
|
+
* Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null.
|
|
152
|
+
*
|
|
153
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
|
|
154
|
+
*
|
|
155
|
+
* @param table the table to join.
|
|
156
|
+
* @param on the `on` clause.
|
|
157
|
+
*
|
|
158
|
+
* @example
|
|
159
|
+
*
|
|
160
|
+
* ```ts
|
|
161
|
+
* // Select all users and their pets
|
|
162
|
+
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
163
|
+
* .from(users)
|
|
164
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
165
|
+
*
|
|
166
|
+
* // Select userId and petId
|
|
167
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
168
|
+
* userId: users.id,
|
|
169
|
+
* petId: pets.id,
|
|
170
|
+
* })
|
|
171
|
+
* .from(users)
|
|
172
|
+
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
173
|
+
* ```
|
|
154
174
|
*/
|
|
155
175
|
leftJoin = this.createJoin("left");
|
|
156
176
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
*
|
|
177
|
+
* Executes a `right join` operation by adding another table to the current query.
|
|
178
|
+
*
|
|
179
|
+
* Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null.
|
|
180
|
+
*
|
|
181
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
|
|
182
|
+
*
|
|
183
|
+
* @param table the table to join.
|
|
184
|
+
* @param on the `on` clause.
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
*
|
|
188
|
+
* ```ts
|
|
189
|
+
* // Select all users and their pets
|
|
190
|
+
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
191
|
+
* .from(users)
|
|
192
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
193
|
+
*
|
|
194
|
+
* // Select userId and petId
|
|
195
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
196
|
+
* userId: users.id,
|
|
197
|
+
* petId: pets.id,
|
|
198
|
+
* })
|
|
199
|
+
* .from(users)
|
|
200
|
+
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
201
|
+
* ```
|
|
161
202
|
*/
|
|
162
203
|
rightJoin = this.createJoin("right");
|
|
163
204
|
/**
|
|
164
|
-
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
205
|
+
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
206
|
+
*
|
|
207
|
+
* Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs.
|
|
208
|
+
*
|
|
209
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
|
|
210
|
+
*
|
|
211
|
+
* @param table the table to join.
|
|
212
|
+
* @param on the `on` clause.
|
|
213
|
+
*
|
|
214
|
+
* @example
|
|
215
|
+
*
|
|
216
|
+
* ```ts
|
|
217
|
+
* // Select all users and their pets
|
|
218
|
+
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
219
|
+
* .from(users)
|
|
220
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
221
|
+
*
|
|
222
|
+
* // Select userId and petId
|
|
223
|
+
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
224
|
+
* userId: users.id,
|
|
225
|
+
* petId: pets.id,
|
|
226
|
+
* })
|
|
227
|
+
* .from(users)
|
|
228
|
+
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
229
|
+
* ```
|
|
169
230
|
*/
|
|
170
231
|
innerJoin = this.createJoin("inner");
|
|
171
232
|
/**
|
|
172
|
-
*
|
|
173
|
-
*
|
|
174
|
-
* rows in
|
|
233
|
+
* Executes a `full join` operation by combining rows from two tables into a new table.
|
|
234
|
+
*
|
|
235
|
+
* Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns.
|
|
236
|
+
*
|
|
237
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
|
|
238
|
+
*
|
|
239
|
+
* @param table the table to join.
|
|
240
|
+
* @param on the `on` clause.
|
|
241
|
+
*
|
|
242
|
+
* @example
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* // Select all users and their pets
|
|
246
|
+
* const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
|
|
247
|
+
* .from(users)
|
|
248
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
249
|
+
*
|
|
250
|
+
* // Select userId and petId
|
|
251
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
|
|
252
|
+
* userId: users.id,
|
|
253
|
+
* petId: pets.id,
|
|
254
|
+
* })
|
|
255
|
+
* .from(users)
|
|
256
|
+
* .fullJoin(pets, eq(users.id, pets.ownerId))
|
|
257
|
+
* ```
|
|
175
258
|
*/
|
|
176
259
|
fullJoin = this.createJoin("full");
|
|
177
260
|
createSetOperator(type, isAll) {
|
|
@@ -186,29 +269,226 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
186
269
|
return this;
|
|
187
270
|
};
|
|
188
271
|
}
|
|
272
|
+
/**
|
|
273
|
+
* Adds `union` set operator to the query.
|
|
274
|
+
*
|
|
275
|
+
* Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
|
|
276
|
+
*
|
|
277
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
*
|
|
281
|
+
* ```ts
|
|
282
|
+
* // Select all unique names from customers and users tables
|
|
283
|
+
* await db.select({ name: users.name })
|
|
284
|
+
* .from(users)
|
|
285
|
+
* .union(
|
|
286
|
+
* db.select({ name: customers.name }).from(customers)
|
|
287
|
+
* );
|
|
288
|
+
* // or
|
|
289
|
+
* import { union } from 'drizzle-orm/pg-core'
|
|
290
|
+
*
|
|
291
|
+
* await union(
|
|
292
|
+
* db.select({ name: users.name }).from(users),
|
|
293
|
+
* db.select({ name: customers.name }).from(customers)
|
|
294
|
+
* );
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
189
297
|
union = this.createSetOperator("union", false);
|
|
298
|
+
/**
|
|
299
|
+
* Adds `union all` set operator to the query.
|
|
300
|
+
*
|
|
301
|
+
* Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
|
|
302
|
+
*
|
|
303
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
|
|
304
|
+
*
|
|
305
|
+
* @example
|
|
306
|
+
*
|
|
307
|
+
* ```ts
|
|
308
|
+
* // Select all transaction ids from both online and in-store sales
|
|
309
|
+
* await db.select({ transaction: onlineSales.transactionId })
|
|
310
|
+
* .from(onlineSales)
|
|
311
|
+
* .unionAll(
|
|
312
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
313
|
+
* );
|
|
314
|
+
* // or
|
|
315
|
+
* import { unionAll } from 'drizzle-orm/pg-core'
|
|
316
|
+
*
|
|
317
|
+
* await unionAll(
|
|
318
|
+
* db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
|
|
319
|
+
* db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
|
|
320
|
+
* );
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
190
323
|
unionAll = this.createSetOperator("union", true);
|
|
324
|
+
/**
|
|
325
|
+
* Adds `intersect` set operator to the query.
|
|
326
|
+
*
|
|
327
|
+
* Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
|
|
328
|
+
*
|
|
329
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
*
|
|
333
|
+
* ```ts
|
|
334
|
+
* // Select course names that are offered in both departments A and B
|
|
335
|
+
* await db.select({ courseName: depA.courseName })
|
|
336
|
+
* .from(depA)
|
|
337
|
+
* .intersect(
|
|
338
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
339
|
+
* );
|
|
340
|
+
* // or
|
|
341
|
+
* import { intersect } from 'drizzle-orm/pg-core'
|
|
342
|
+
*
|
|
343
|
+
* await intersect(
|
|
344
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
345
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
346
|
+
* );
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
191
349
|
intersect = this.createSetOperator("intersect", false);
|
|
350
|
+
/**
|
|
351
|
+
* Adds `intersect all` set operator to the query.
|
|
352
|
+
*
|
|
353
|
+
* Calling this method will retain only the rows that are present in both result sets including all duplicates.
|
|
354
|
+
*
|
|
355
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
|
|
356
|
+
*
|
|
357
|
+
* @example
|
|
358
|
+
*
|
|
359
|
+
* ```ts
|
|
360
|
+
* // Select all products and quantities that are ordered by both regular and VIP customers
|
|
361
|
+
* await db.select({
|
|
362
|
+
* productId: regularCustomerOrders.productId,
|
|
363
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
364
|
+
* })
|
|
365
|
+
* .from(regularCustomerOrders)
|
|
366
|
+
* .intersectAll(
|
|
367
|
+
* db.select({
|
|
368
|
+
* productId: vipCustomerOrders.productId,
|
|
369
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
370
|
+
* })
|
|
371
|
+
* .from(vipCustomerOrders)
|
|
372
|
+
* );
|
|
373
|
+
* // or
|
|
374
|
+
* import { intersectAll } from 'drizzle-orm/pg-core'
|
|
375
|
+
*
|
|
376
|
+
* await intersectAll(
|
|
377
|
+
* db.select({
|
|
378
|
+
* productId: regularCustomerOrders.productId,
|
|
379
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
380
|
+
* })
|
|
381
|
+
* .from(regularCustomerOrders),
|
|
382
|
+
* db.select({
|
|
383
|
+
* productId: vipCustomerOrders.productId,
|
|
384
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
385
|
+
* })
|
|
386
|
+
* .from(vipCustomerOrders)
|
|
387
|
+
* );
|
|
388
|
+
* ```
|
|
389
|
+
*/
|
|
192
390
|
intersectAll = this.createSetOperator("intersect", true);
|
|
391
|
+
/**
|
|
392
|
+
* Adds `except` set operator to the query.
|
|
393
|
+
*
|
|
394
|
+
* Calling this method will retrieve all unique rows from the left query, except for the rows that are present in the result set of the right query.
|
|
395
|
+
*
|
|
396
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
*
|
|
400
|
+
* ```ts
|
|
401
|
+
* // Select all courses offered in department A but not in department B
|
|
402
|
+
* await db.select({ courseName: depA.courseName })
|
|
403
|
+
* .from(depA)
|
|
404
|
+
* .except(
|
|
405
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
406
|
+
* );
|
|
407
|
+
* // or
|
|
408
|
+
* import { except } from 'drizzle-orm/pg-core'
|
|
409
|
+
*
|
|
410
|
+
* await except(
|
|
411
|
+
* db.select({ courseName: depA.courseName }).from(depA),
|
|
412
|
+
* db.select({ courseName: depB.courseName }).from(depB)
|
|
413
|
+
* );
|
|
414
|
+
* ```
|
|
415
|
+
*/
|
|
193
416
|
except = this.createSetOperator("except", false);
|
|
417
|
+
/**
|
|
418
|
+
* Adds `except all` set operator to the query.
|
|
419
|
+
*
|
|
420
|
+
* Calling this method will retrieve all rows from the left query, except for the rows that are present in the result set of the right query.
|
|
421
|
+
*
|
|
422
|
+
* See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
|
|
423
|
+
*
|
|
424
|
+
* @example
|
|
425
|
+
*
|
|
426
|
+
* ```ts
|
|
427
|
+
* // Select all products that are ordered by regular customers but not by VIP customers
|
|
428
|
+
* await db.select({
|
|
429
|
+
* productId: regularCustomerOrders.productId,
|
|
430
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered,
|
|
431
|
+
* })
|
|
432
|
+
* .from(regularCustomerOrders)
|
|
433
|
+
* .exceptAll(
|
|
434
|
+
* db.select({
|
|
435
|
+
* productId: vipCustomerOrders.productId,
|
|
436
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered,
|
|
437
|
+
* })
|
|
438
|
+
* .from(vipCustomerOrders)
|
|
439
|
+
* );
|
|
440
|
+
* // or
|
|
441
|
+
* import { exceptAll } from 'drizzle-orm/pg-core'
|
|
442
|
+
*
|
|
443
|
+
* await exceptAll(
|
|
444
|
+
* db.select({
|
|
445
|
+
* productId: regularCustomerOrders.productId,
|
|
446
|
+
* quantityOrdered: regularCustomerOrders.quantityOrdered
|
|
447
|
+
* })
|
|
448
|
+
* .from(regularCustomerOrders),
|
|
449
|
+
* db.select({
|
|
450
|
+
* productId: vipCustomerOrders.productId,
|
|
451
|
+
* quantityOrdered: vipCustomerOrders.quantityOrdered
|
|
452
|
+
* })
|
|
453
|
+
* .from(vipCustomerOrders)
|
|
454
|
+
* );
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
194
457
|
exceptAll = this.createSetOperator("except", true);
|
|
195
458
|
/** @internal */
|
|
196
459
|
addSetOperators(setOperators) {
|
|
197
460
|
this.config.setOperators.push(...setOperators);
|
|
198
461
|
return this;
|
|
199
462
|
}
|
|
200
|
-
/**
|
|
201
|
-
*
|
|
202
|
-
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
463
|
+
/**
|
|
464
|
+
* Adds a `where` clause to the query.
|
|
465
|
+
*
|
|
466
|
+
* Calling this method will select only those rows that fulfill a specified condition.
|
|
467
|
+
*
|
|
468
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#filtering}
|
|
469
|
+
*
|
|
470
|
+
* @param where the `where` clause.
|
|
471
|
+
*
|
|
472
|
+
* @example
|
|
473
|
+
* You can use conditional operators and `sql function` to filter the rows to be selected.
|
|
474
|
+
*
|
|
207
475
|
* ```ts
|
|
208
|
-
* //
|
|
209
|
-
* db.select().from(cars).where(eq(cars.
|
|
476
|
+
* // Select all cars with green color
|
|
477
|
+
* await db.select().from(cars).where(eq(cars.color, 'green'));
|
|
478
|
+
* // or
|
|
479
|
+
* await db.select().from(cars).where(sql`${cars.color} = 'green'`)
|
|
210
480
|
* ```
|
|
211
|
-
|
|
481
|
+
*
|
|
482
|
+
* You can logically combine conditional operators with `and()` and `or()` operators:
|
|
483
|
+
*
|
|
484
|
+
* ```ts
|
|
485
|
+
* // Select all BMW cars with a green color
|
|
486
|
+
* await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
|
|
487
|
+
*
|
|
488
|
+
* // Select all cars with the green or blue color
|
|
489
|
+
* await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
|
|
490
|
+
* ```
|
|
491
|
+
*/
|
|
212
492
|
where(where) {
|
|
213
493
|
if (typeof where === "function") {
|
|
214
494
|
where = where(
|
|
@@ -222,11 +502,26 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
222
502
|
return this;
|
|
223
503
|
}
|
|
224
504
|
/**
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
* {@link https://
|
|
505
|
+
* Adds a `having` clause to the query.
|
|
506
|
+
*
|
|
507
|
+
* Calling this method will select only those rows that fulfill a specified condition. It is typically used with aggregate functions to filter the aggregated data based on a specified condition.
|
|
508
|
+
*
|
|
509
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
|
|
510
|
+
*
|
|
511
|
+
* @param having the `having` clause.
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
*
|
|
515
|
+
* ```ts
|
|
516
|
+
* // Select all brands with more than one car
|
|
517
|
+
* await db.select({
|
|
518
|
+
* brand: cars.brand,
|
|
519
|
+
* count: sql<number>`cast(count(${cars.id}) as int)`,
|
|
520
|
+
* })
|
|
521
|
+
* .from(cars)
|
|
522
|
+
* .groupBy(cars.brand)
|
|
523
|
+
* .having(({ count }) => gt(count, 1));
|
|
524
|
+
* ```
|
|
230
525
|
*/
|
|
231
526
|
having(having) {
|
|
232
527
|
if (typeof having === "function") {
|
|
@@ -279,17 +574,20 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
279
574
|
return this;
|
|
280
575
|
}
|
|
281
576
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
577
|
+
* Adds a `limit` clause to the query.
|
|
578
|
+
*
|
|
579
|
+
* Calling this method will set the maximum number of rows that will be returned by this query.
|
|
284
580
|
*
|
|
285
|
-
*
|
|
581
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
582
|
+
*
|
|
583
|
+
* @param limit the `limit` clause.
|
|
584
|
+
*
|
|
585
|
+
* @example
|
|
286
586
|
*
|
|
287
587
|
* ```ts
|
|
288
588
|
* // Get the first 10 people from this query.
|
|
289
|
-
* db.select().from(people).limit(10);
|
|
589
|
+
* await db.select().from(people).limit(10);
|
|
290
590
|
* ```
|
|
291
|
-
*
|
|
292
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-LIMIT | Postgres LIMIT documentation}
|
|
293
591
|
*/
|
|
294
592
|
limit(limit) {
|
|
295
593
|
if (this.config.setOperators.length > 0) {
|
|
@@ -300,14 +598,19 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
300
598
|
return this;
|
|
301
599
|
}
|
|
302
600
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
601
|
+
* Adds an `offset` clause to the query.
|
|
602
|
+
*
|
|
603
|
+
* Calling this method will skip a number of rows when returning results from this query.
|
|
604
|
+
*
|
|
605
|
+
* See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
|
|
606
|
+
*
|
|
607
|
+
* @param offset the `offset` clause.
|
|
608
|
+
*
|
|
609
|
+
* @example
|
|
307
610
|
*
|
|
308
611
|
* ```ts
|
|
309
612
|
* // Get the 10th-20th people from this query.
|
|
310
|
-
* db.select().from(people).offset(10).limit(10);
|
|
613
|
+
* await db.select().from(people).offset(10).limit(10);
|
|
311
614
|
* ```
|
|
312
615
|
*/
|
|
313
616
|
offset(offset) {
|
|
@@ -319,11 +622,14 @@ class PgSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
319
622
|
return this;
|
|
320
623
|
}
|
|
321
624
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* the rows being queried.
|
|
325
|
-
*
|
|
326
|
-
* {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE
|
|
625
|
+
* Adds a `for` clause to the query.
|
|
626
|
+
*
|
|
627
|
+
* Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.
|
|
628
|
+
*
|
|
629
|
+
* See docs: {@link https://www.postgresql.org/docs/current/sql-select.html#SQL-FOR-UPDATE-SHARE}
|
|
630
|
+
*
|
|
631
|
+
* @param strength the lock strength.
|
|
632
|
+
* @param config the lock configuration.
|
|
327
633
|
*/
|
|
328
634
|
for(strength, config = {}) {
|
|
329
635
|
this.config.lockingClause = { strength, config };
|