drizzle-orm 0.29.0 → 0.29.1-e78b53e

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.
Files changed (146) hide show
  1. package/mysql-core/db.cjs +134 -31
  2. package/mysql-core/db.cjs.map +1 -1
  3. package/mysql-core/db.d.cts +171 -1
  4. package/mysql-core/db.d.ts +171 -1
  5. package/mysql-core/db.js +134 -31
  6. package/mysql-core/db.js.map +1 -1
  7. package/mysql-core/query-builders/delete.cjs +29 -0
  8. package/mysql-core/query-builders/delete.cjs.map +1 -1
  9. package/mysql-core/query-builders/delete.d.cts +29 -0
  10. package/mysql-core/query-builders/delete.d.ts +29 -0
  11. package/mysql-core/query-builders/delete.js +29 -0
  12. package/mysql-core/query-builders/delete.js.map +1 -1
  13. package/mysql-core/query-builders/insert.cjs +26 -0
  14. package/mysql-core/query-builders/insert.cjs.map +1 -1
  15. package/mysql-core/query-builders/insert.d.cts +26 -0
  16. package/mysql-core/query-builders/insert.d.ts +26 -0
  17. package/mysql-core/query-builders/insert.js +26 -0
  18. package/mysql-core/query-builders/insert.js.map +1 -1
  19. package/mysql-core/query-builders/query.cjs +9 -1
  20. package/mysql-core/query-builders/query.cjs.map +1 -1
  21. package/mysql-core/query-builders/query.d.cts +1 -0
  22. package/mysql-core/query-builders/query.d.ts +1 -0
  23. package/mysql-core/query-builders/query.js +9 -1
  24. package/mysql-core/query-builders/query.js.map +1 -1
  25. package/mysql-core/query-builders/select.cjs +381 -0
  26. package/mysql-core/query-builders/select.cjs.map +1 -1
  27. package/mysql-core/query-builders/select.d.cts +604 -0
  28. package/mysql-core/query-builders/select.d.ts +604 -0
  29. package/mysql-core/query-builders/select.js +381 -0
  30. package/mysql-core/query-builders/select.js.map +1 -1
  31. package/mysql-core/query-builders/update.cjs +33 -0
  32. package/mysql-core/query-builders/update.cjs.map +1 -1
  33. package/mysql-core/query-builders/update.d.cts +33 -0
  34. package/mysql-core/query-builders/update.d.ts +33 -0
  35. package/mysql-core/query-builders/update.js +33 -0
  36. package/mysql-core/query-builders/update.js.map +1 -1
  37. package/mysql-core/view.cjs +2 -2
  38. package/mysql-core/view.cjs.map +1 -1
  39. package/mysql-core/view.d.cts +1 -1
  40. package/mysql-core/view.d.ts +1 -1
  41. package/mysql-core/view.js +2 -2
  42. package/mysql-core/view.js.map +1 -1
  43. package/mysql-proxy/migrator.cjs +2 -2
  44. package/mysql-proxy/migrator.cjs.map +1 -1
  45. package/mysql-proxy/migrator.js +2 -2
  46. package/mysql-proxy/migrator.js.map +1 -1
  47. package/package.json +25 -1
  48. package/pg-core/db.cjs +153 -34
  49. package/pg-core/db.cjs.map +1 -1
  50. package/pg-core/db.d.cts +211 -0
  51. package/pg-core/db.d.ts +211 -0
  52. package/pg-core/db.js +153 -34
  53. package/pg-core/db.js.map +1 -1
  54. package/pg-core/dialect.cjs +1 -1
  55. package/pg-core/dialect.cjs.map +1 -1
  56. package/pg-core/dialect.js +1 -1
  57. package/pg-core/dialect.js.map +1 -1
  58. package/pg-core/query-builders/delete.cjs +29 -0
  59. package/pg-core/query-builders/delete.cjs.map +1 -1
  60. package/pg-core/query-builders/delete.d.cts +49 -0
  61. package/pg-core/query-builders/delete.d.ts +49 -0
  62. package/pg-core/query-builders/delete.js +29 -0
  63. package/pg-core/query-builders/delete.js.map +1 -1
  64. package/pg-core/query-builders/insert.cjs +51 -0
  65. package/pg-core/query-builders/insert.cjs.map +1 -1
  66. package/pg-core/query-builders/insert.d.cts +71 -0
  67. package/pg-core/query-builders/insert.d.ts +71 -0
  68. package/pg-core/query-builders/insert.js +51 -0
  69. package/pg-core/query-builders/insert.js.map +1 -1
  70. package/pg-core/query-builders/query.cjs +9 -2
  71. package/pg-core/query-builders/query.cjs.map +1 -1
  72. package/pg-core/query-builders/query.d.cts +1 -0
  73. package/pg-core/query-builders/query.d.ts +1 -0
  74. package/pg-core/query-builders/query.js +9 -2
  75. package/pg-core/query-builders/query.js.map +1 -1
  76. package/pg-core/query-builders/select.cjs +354 -48
  77. package/pg-core/query-builders/select.cjs.map +1 -1
  78. package/pg-core/query-builders/select.d.cts +555 -59
  79. package/pg-core/query-builders/select.d.ts +555 -59
  80. package/pg-core/query-builders/select.js +354 -48
  81. package/pg-core/query-builders/select.js.map +1 -1
  82. package/pg-core/query-builders/update.cjs +33 -0
  83. package/pg-core/query-builders/update.cjs.map +1 -1
  84. package/pg-core/query-builders/update.d.cts +55 -0
  85. package/pg-core/query-builders/update.d.ts +55 -0
  86. package/pg-core/query-builders/update.js +33 -0
  87. package/pg-core/query-builders/update.js.map +1 -1
  88. package/pg-proxy/migrator.cjs +1 -1
  89. package/pg-proxy/migrator.cjs.map +1 -1
  90. package/pg-proxy/migrator.js +1 -1
  91. package/pg-proxy/migrator.js.map +1 -1
  92. package/sql/functions/aggregate.cjs +69 -0
  93. package/sql/functions/aggregate.cjs.map +1 -0
  94. package/sql/functions/aggregate.d.cts +104 -0
  95. package/sql/functions/aggregate.d.ts +104 -0
  96. package/sql/functions/aggregate.js +38 -0
  97. package/sql/functions/aggregate.js.map +1 -0
  98. package/sql/functions/index.cjs +23 -0
  99. package/sql/functions/index.cjs.map +1 -0
  100. package/sql/functions/index.d.cts +1 -0
  101. package/sql/functions/index.d.ts +1 -0
  102. package/sql/functions/index.js +2 -0
  103. package/sql/functions/index.js.map +1 -0
  104. package/sql/index.cjs +3 -1
  105. package/sql/index.cjs.map +1 -1
  106. package/sql/index.d.cts +1 -0
  107. package/sql/index.d.ts +1 -0
  108. package/sql/index.js +1 -0
  109. package/sql/index.js.map +1 -1
  110. package/sql/sql.cjs.map +1 -1
  111. package/sql/sql.js.map +1 -1
  112. package/sqlite-core/db.cjs +155 -36
  113. package/sqlite-core/db.cjs.map +1 -1
  114. package/sqlite-core/db.d.cts +187 -0
  115. package/sqlite-core/db.d.ts +187 -0
  116. package/sqlite-core/db.js +155 -36
  117. package/sqlite-core/db.js.map +1 -1
  118. package/sqlite-core/query-builders/delete.cjs +29 -0
  119. package/sqlite-core/query-builders/delete.cjs.map +1 -1
  120. package/sqlite-core/query-builders/delete.d.cts +49 -0
  121. package/sqlite-core/query-builders/delete.d.ts +49 -0
  122. package/sqlite-core/query-builders/delete.js +29 -0
  123. package/sqlite-core/query-builders/delete.js.map +1 -1
  124. package/sqlite-core/query-builders/insert.cjs +51 -0
  125. package/sqlite-core/query-builders/insert.cjs.map +1 -1
  126. package/sqlite-core/query-builders/insert.d.cts +71 -0
  127. package/sqlite-core/query-builders/insert.d.ts +71 -0
  128. package/sqlite-core/query-builders/insert.js +51 -0
  129. package/sqlite-core/query-builders/insert.js.map +1 -1
  130. package/sqlite-core/query-builders/select.cjs +291 -0
  131. package/sqlite-core/query-builders/select.cjs.map +1 -1
  132. package/sqlite-core/query-builders/select.d.cts +434 -0
  133. package/sqlite-core/query-builders/select.d.ts +434 -0
  134. package/sqlite-core/query-builders/select.js +291 -0
  135. package/sqlite-core/query-builders/select.js.map +1 -1
  136. package/sqlite-core/query-builders/select.types.cjs.map +1 -1
  137. package/sqlite-core/query-builders/update.cjs +33 -0
  138. package/sqlite-core/query-builders/update.cjs.map +1 -1
  139. package/sqlite-core/query-builders/update.d.cts +55 -0
  140. package/sqlite-core/query-builders/update.d.ts +55 -0
  141. package/sqlite-core/query-builders/update.js +33 -0
  142. package/sqlite-core/query-builders/update.js.map +1 -1
  143. package/version.cjs +1 -1
  144. package/version.d.cts +1 -1
  145. package/version.d.ts +1 -1
  146. package/version.js +1 -1
@@ -58,25 +58,449 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
58
58
  distinct: boolean | undefined;
59
59
  });
60
60
  private createJoin;
61
+ /**
62
+ * Executes a `left join` operation by adding another table to the current query.
63
+ *
64
+ * 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.
65
+ *
66
+ * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}
67
+ *
68
+ * @param table the table to join.
69
+ * @param on the `on` clause.
70
+ *
71
+ * @example
72
+ *
73
+ * ```ts
74
+ * // Select all users and their pets
75
+ * const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
76
+ * .from(users)
77
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
78
+ *
79
+ * // Select userId and petId
80
+ * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
81
+ * userId: users.id,
82
+ * petId: pets.id,
83
+ * })
84
+ * .from(users)
85
+ * .leftJoin(pets, eq(users.id, pets.ownerId))
86
+ * ```
87
+ */
61
88
  leftJoin: MySqlJoinFn<this, TDynamic, "left">;
89
+ /**
90
+ * Executes a `right join` operation by adding another table to the current query.
91
+ *
92
+ * 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.
93
+ *
94
+ * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}
95
+ *
96
+ * @param table the table to join.
97
+ * @param on the `on` clause.
98
+ *
99
+ * @example
100
+ *
101
+ * ```ts
102
+ * // Select all users and their pets
103
+ * const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
104
+ * .from(users)
105
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
106
+ *
107
+ * // Select userId and petId
108
+ * const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
109
+ * userId: users.id,
110
+ * petId: pets.id,
111
+ * })
112
+ * .from(users)
113
+ * .rightJoin(pets, eq(users.id, pets.ownerId))
114
+ * ```
115
+ */
62
116
  rightJoin: MySqlJoinFn<this, TDynamic, "right">;
117
+ /**
118
+ * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
119
+ *
120
+ * 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.
121
+ *
122
+ * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}
123
+ *
124
+ * @param table the table to join.
125
+ * @param on the `on` clause.
126
+ *
127
+ * @example
128
+ *
129
+ * ```ts
130
+ * // Select all users and their pets
131
+ * const usersWithPets: { user: User; pets: Pet }[] = await db.select()
132
+ * .from(users)
133
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
134
+ *
135
+ * // Select userId and petId
136
+ * const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
137
+ * userId: users.id,
138
+ * petId: pets.id,
139
+ * })
140
+ * .from(users)
141
+ * .innerJoin(pets, eq(users.id, pets.ownerId))
142
+ * ```
143
+ */
63
144
  innerJoin: MySqlJoinFn<this, TDynamic, "inner">;
145
+ /**
146
+ * Executes a `full join` operation by combining rows from two tables into a new table.
147
+ *
148
+ * 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.
149
+ *
150
+ * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}
151
+ *
152
+ * @param table the table to join.
153
+ * @param on the `on` clause.
154
+ *
155
+ * @example
156
+ *
157
+ * ```ts
158
+ * // Select all users and their pets
159
+ * const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
160
+ * .from(users)
161
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
162
+ *
163
+ * // Select userId and petId
164
+ * const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
165
+ * userId: users.id,
166
+ * petId: pets.id,
167
+ * })
168
+ * .from(users)
169
+ * .fullJoin(pets, eq(users.id, pets.ownerId))
170
+ * ```
171
+ */
64
172
  fullJoin: MySqlJoinFn<this, TDynamic, "full">;
65
173
  private createSetOperator;
174
+ /**
175
+ * Adds `union` set operator to the query.
176
+ *
177
+ * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
178
+ *
179
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
180
+ *
181
+ * @example
182
+ *
183
+ * ```ts
184
+ * // Select all unique names from customers and users tables
185
+ * await db.select({ name: users.name })
186
+ * .from(users)
187
+ * .union(
188
+ * db.select({ name: customers.name }).from(customers)
189
+ * );
190
+ * // or
191
+ * import { union } from 'drizzle-orm/mysql-core'
192
+ *
193
+ * await union(
194
+ * db.select({ name: users.name }).from(users),
195
+ * db.select({ name: customers.name }).from(customers)
196
+ * );
197
+ * ```
198
+ */
66
199
  union: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
200
+ /**
201
+ * Adds `union all` set operator to the query.
202
+ *
203
+ * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
204
+ *
205
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
206
+ *
207
+ * @example
208
+ *
209
+ * ```ts
210
+ * // Select all transaction ids from both online and in-store sales
211
+ * await db.select({ transaction: onlineSales.transactionId })
212
+ * .from(onlineSales)
213
+ * .unionAll(
214
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
215
+ * );
216
+ * // or
217
+ * import { unionAll } from 'drizzle-orm/mysql-core'
218
+ *
219
+ * await unionAll(
220
+ * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
221
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
222
+ * );
223
+ * ```
224
+ */
67
225
  unionAll: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
226
+ /**
227
+ * Adds `intersect` set operator to the query.
228
+ *
229
+ * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
230
+ *
231
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
232
+ *
233
+ * @example
234
+ *
235
+ * ```ts
236
+ * // Select course names that are offered in both departments A and B
237
+ * await db.select({ courseName: depA.courseName })
238
+ * .from(depA)
239
+ * .intersect(
240
+ * db.select({ courseName: depB.courseName }).from(depB)
241
+ * );
242
+ * // or
243
+ * import { intersect } from 'drizzle-orm/mysql-core'
244
+ *
245
+ * await intersect(
246
+ * db.select({ courseName: depA.courseName }).from(depA),
247
+ * db.select({ courseName: depB.courseName }).from(depB)
248
+ * );
249
+ * ```
250
+ */
68
251
  intersect: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
252
+ /**
253
+ * Adds `intersect all` set operator to the query.
254
+ *
255
+ * Calling this method will retain only the rows that are present in both result sets including all duplicates.
256
+ *
257
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
258
+ *
259
+ * @example
260
+ *
261
+ * ```ts
262
+ * // Select all products and quantities that are ordered by both regular and VIP customers
263
+ * await db.select({
264
+ * productId: regularCustomerOrders.productId,
265
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
266
+ * })
267
+ * .from(regularCustomerOrders)
268
+ * .intersectAll(
269
+ * db.select({
270
+ * productId: vipCustomerOrders.productId,
271
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
272
+ * })
273
+ * .from(vipCustomerOrders)
274
+ * );
275
+ * // or
276
+ * import { intersectAll } from 'drizzle-orm/mysql-core'
277
+ *
278
+ * await intersectAll(
279
+ * db.select({
280
+ * productId: regularCustomerOrders.productId,
281
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
282
+ * })
283
+ * .from(regularCustomerOrders),
284
+ * db.select({
285
+ * productId: vipCustomerOrders.productId,
286
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
287
+ * })
288
+ * .from(vipCustomerOrders)
289
+ * );
290
+ * ```
291
+ */
69
292
  intersectAll: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
293
+ /**
294
+ * Adds `except` set operator to the query.
295
+ *
296
+ * 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.
297
+ *
298
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
299
+ *
300
+ * @example
301
+ *
302
+ * ```ts
303
+ * // Select all courses offered in department A but not in department B
304
+ * await db.select({ courseName: depA.courseName })
305
+ * .from(depA)
306
+ * .except(
307
+ * db.select({ courseName: depB.courseName }).from(depB)
308
+ * );
309
+ * // or
310
+ * import { except } from 'drizzle-orm/mysql-core'
311
+ *
312
+ * await except(
313
+ * db.select({ courseName: depA.courseName }).from(depA),
314
+ * db.select({ courseName: depB.courseName }).from(depB)
315
+ * );
316
+ * ```
317
+ */
70
318
  except: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
319
+ /**
320
+ * Adds `except all` set operator to the query.
321
+ *
322
+ * 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.
323
+ *
324
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
325
+ *
326
+ * @example
327
+ *
328
+ * ```ts
329
+ * // Select all products that are ordered by regular customers but not by VIP customers
330
+ * await db.select({
331
+ * productId: regularCustomerOrders.productId,
332
+ * quantityOrdered: regularCustomerOrders.quantityOrdered,
333
+ * })
334
+ * .from(regularCustomerOrders)
335
+ * .exceptAll(
336
+ * db.select({
337
+ * productId: vipCustomerOrders.productId,
338
+ * quantityOrdered: vipCustomerOrders.quantityOrdered,
339
+ * })
340
+ * .from(vipCustomerOrders)
341
+ * );
342
+ * // or
343
+ * import { exceptAll } from 'drizzle-orm/mysql-core'
344
+ *
345
+ * await exceptAll(
346
+ * db.select({
347
+ * productId: regularCustomerOrders.productId,
348
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
349
+ * })
350
+ * .from(regularCustomerOrders),
351
+ * db.select({
352
+ * productId: vipCustomerOrders.productId,
353
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
354
+ * })
355
+ * .from(vipCustomerOrders)
356
+ * );
357
+ * ```
358
+ */
71
359
  exceptAll: <TValue extends MySqlSetOperatorWithResult<TResult>>(rightSelection: ((setOperators: GetMySqlSetOperators) => SetOperatorRightSelect<TValue, TResult>) | SetOperatorRightSelect<TValue, TResult>) => MySqlSelectWithout<this, TDynamic, MySqlSetOperatorExcludedMethods, true>;
360
+ /**
361
+ * Adds a `where` clause to the query.
362
+ *
363
+ * Calling this method will select only those rows that fulfill a specified condition.
364
+ *
365
+ * See docs: {@link https://orm.drizzle.team/docs/select#filtering}
366
+ *
367
+ * @param where the `where` clause.
368
+ *
369
+ * @example
370
+ * You can use conditional operators and `sql function` to filter the rows to be selected.
371
+ *
372
+ * ```ts
373
+ * // Select all cars with green color
374
+ * await db.select().from(cars).where(eq(cars.color, 'green'));
375
+ * // or
376
+ * await db.select().from(cars).where(sql`${cars.color} = 'green'`)
377
+ * ```
378
+ *
379
+ * You can logically combine conditional operators with `and()` and `or()` operators:
380
+ *
381
+ * ```ts
382
+ * // Select all BMW cars with a green color
383
+ * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));
384
+ *
385
+ * // Select all cars with the green or blue color
386
+ * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));
387
+ * ```
388
+ */
72
389
  where(where: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): MySqlSelectWithout<this, TDynamic, 'where'>;
390
+ /**
391
+ * Adds a `having` clause to the query.
392
+ *
393
+ * 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.
394
+ *
395
+ * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
396
+ *
397
+ * @param having the `having` clause.
398
+ *
399
+ * @example
400
+ *
401
+ * ```ts
402
+ * // Select all brands with more than one car
403
+ * await db.select({
404
+ * brand: cars.brand,
405
+ * count: sql<number>`cast(count(${cars.id}) as int)`,
406
+ * })
407
+ * .from(cars)
408
+ * .groupBy(cars.brand)
409
+ * .having(({ count }) => gt(count, 1));
410
+ * ```
411
+ */
73
412
  having(having: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined): MySqlSelectWithout<this, TDynamic, 'having'>;
413
+ /**
414
+ * Adds a `group by` clause to the query.
415
+ *
416
+ * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.
417
+ *
418
+ * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}
419
+ *
420
+ * @example
421
+ *
422
+ * ```ts
423
+ * // Group and count people by their last names
424
+ * await db.select({
425
+ * lastName: people.lastName,
426
+ * count: sql<number>`cast(count(*) as int)`
427
+ * })
428
+ * .from(people)
429
+ * .groupBy(people.lastName);
430
+ * ```
431
+ */
74
432
  groupBy(builder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>): MySqlSelectWithout<this, TDynamic, 'groupBy'>;
75
433
  groupBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'groupBy'>;
434
+ /**
435
+ * Adds an `order by` clause to the query.
436
+ *
437
+ * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.
438
+ *
439
+ * See docs: {@link https://orm.drizzle.team/docs/select#order-by}
440
+ *
441
+ * @example
442
+ *
443
+ * ```
444
+ * // Select cars ordered by year
445
+ * await db.select().from(cars).orderBy(cars.year);
446
+ * ```
447
+ *
448
+ * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.
449
+ *
450
+ * ```ts
451
+ * // Select cars ordered by year in descending order
452
+ * await db.select().from(cars).orderBy(desc(cars.year));
453
+ *
454
+ * // Select cars ordered by year and price
455
+ * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));
456
+ * ```
457
+ */
76
458
  orderBy(builder: (aliases: this['_']['selection']) => ValueOrArray<MySqlColumn | SQL | SQL.Aliased>): MySqlSelectWithout<this, TDynamic, 'orderBy'>;
77
459
  orderBy(...columns: (MySqlColumn | SQL | SQL.Aliased)[]): MySqlSelectWithout<this, TDynamic, 'orderBy'>;
460
+ /**
461
+ * Adds a `limit` clause to the query.
462
+ *
463
+ * Calling this method will set the maximum number of rows that will be returned by this query.
464
+ *
465
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
466
+ *
467
+ * @param limit the `limit` clause.
468
+ *
469
+ * @example
470
+ *
471
+ * ```ts
472
+ * // Get the first 10 people from this query.
473
+ * await db.select().from(people).limit(10);
474
+ * ```
475
+ */
78
476
  limit(limit: number): MySqlSelectWithout<this, TDynamic, 'limit'>;
477
+ /**
478
+ * Adds an `offset` clause to the query.
479
+ *
480
+ * Calling this method will skip a number of rows when returning results from this query.
481
+ *
482
+ * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}
483
+ *
484
+ * @param offset the `offset` clause.
485
+ *
486
+ * @example
487
+ *
488
+ * ```ts
489
+ * // Get the 10th-20th people from this query.
490
+ * await db.select().from(people).offset(10).limit(10);
491
+ * ```
492
+ */
79
493
  offset(offset: number): MySqlSelectWithout<this, TDynamic, 'offset'>;
494
+ /**
495
+ * Adds a `for` clause to the query.
496
+ *
497
+ * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.
498
+ *
499
+ * See docs: {@link https://dev.mysql.com/doc/refman/8.0/en/innodb-locking-reads.html}
500
+ *
501
+ * @param strength the lock strength.
502
+ * @param config the lock configuration.
503
+ */
80
504
  for(strength: LockStrength, config?: LockConfig): MySqlSelectWithout<this, TDynamic, 'for'>;
81
505
  toSQL(): Query;
82
506
  as<TAlias extends string>(alias: TAlias): SubqueryWithSelection<this['_']['selectedFields'], TAlias>;
@@ -91,9 +515,189 @@ export declare class MySqlSelectBase<TTableName extends string | undefined, TSel
91
515
  private createIterator;
92
516
  iterator: ReturnType<this["prepare"]>["iterator"];
93
517
  }
518
+ /**
519
+ * Adds `union` set operator to the query.
520
+ *
521
+ * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.
522
+ *
523
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}
524
+ *
525
+ * @example
526
+ *
527
+ * ```ts
528
+ * // Select all unique names from customers and users tables
529
+ * import { union } from 'drizzle-orm/mysql-core'
530
+ *
531
+ * await union(
532
+ * db.select({ name: users.name }).from(users),
533
+ * db.select({ name: customers.name }).from(customers)
534
+ * );
535
+ * // or
536
+ * await db.select({ name: users.name })
537
+ * .from(users)
538
+ * .union(
539
+ * db.select({ name: customers.name }).from(customers)
540
+ * );
541
+ * ```
542
+ */
94
543
  export declare const union: MySqlCreateSetOperatorFn;
544
+ /**
545
+ * Adds `union all` set operator to the query.
546
+ *
547
+ * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.
548
+ *
549
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}
550
+ *
551
+ * @example
552
+ *
553
+ * ```ts
554
+ * // Select all transaction ids from both online and in-store sales
555
+ * import { unionAll } from 'drizzle-orm/mysql-core'
556
+ *
557
+ * await unionAll(
558
+ * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),
559
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
560
+ * );
561
+ * // or
562
+ * await db.select({ transaction: onlineSales.transactionId })
563
+ * .from(onlineSales)
564
+ * .unionAll(
565
+ * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)
566
+ * );
567
+ * ```
568
+ */
95
569
  export declare const unionAll: MySqlCreateSetOperatorFn;
570
+ /**
571
+ * Adds `intersect` set operator to the query.
572
+ *
573
+ * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.
574
+ *
575
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}
576
+ *
577
+ * @example
578
+ *
579
+ * ```ts
580
+ * // Select course names that are offered in both departments A and B
581
+ * import { intersect } from 'drizzle-orm/mysql-core'
582
+ *
583
+ * await intersect(
584
+ * db.select({ courseName: depA.courseName }).from(depA),
585
+ * db.select({ courseName: depB.courseName }).from(depB)
586
+ * );
587
+ * // or
588
+ * await db.select({ courseName: depA.courseName })
589
+ * .from(depA)
590
+ * .intersect(
591
+ * db.select({ courseName: depB.courseName }).from(depB)
592
+ * );
593
+ * ```
594
+ */
96
595
  export declare const intersect: MySqlCreateSetOperatorFn;
596
+ /**
597
+ * Adds `intersect all` set operator to the query.
598
+ *
599
+ * Calling this method will retain only the rows that are present in both result sets including all duplicates.
600
+ *
601
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect-all}
602
+ *
603
+ * @example
604
+ *
605
+ * ```ts
606
+ * // Select all products and quantities that are ordered by both regular and VIP customers
607
+ * import { intersectAll } from 'drizzle-orm/mysql-core'
608
+ *
609
+ * await intersectAll(
610
+ * db.select({
611
+ * productId: regularCustomerOrders.productId,
612
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
613
+ * })
614
+ * .from(regularCustomerOrders),
615
+ * db.select({
616
+ * productId: vipCustomerOrders.productId,
617
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
618
+ * })
619
+ * .from(vipCustomerOrders)
620
+ * );
621
+ * // or
622
+ * await db.select({
623
+ * productId: regularCustomerOrders.productId,
624
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
625
+ * })
626
+ * .from(regularCustomerOrders)
627
+ * .intersectAll(
628
+ * db.select({
629
+ * productId: vipCustomerOrders.productId,
630
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
631
+ * })
632
+ * .from(vipCustomerOrders)
633
+ * );
634
+ * ```
635
+ */
97
636
  export declare const intersectAll: MySqlCreateSetOperatorFn;
637
+ /**
638
+ * Adds `except` set operator to the query.
639
+ *
640
+ * 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.
641
+ *
642
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}
643
+ *
644
+ * @example
645
+ *
646
+ * ```ts
647
+ * // Select all courses offered in department A but not in department B
648
+ * import { except } from 'drizzle-orm/mysql-core'
649
+ *
650
+ * await except(
651
+ * db.select({ courseName: depA.courseName }).from(depA),
652
+ * db.select({ courseName: depB.courseName }).from(depB)
653
+ * );
654
+ * // or
655
+ * await db.select({ courseName: depA.courseName })
656
+ * .from(depA)
657
+ * .except(
658
+ * db.select({ courseName: depB.courseName }).from(depB)
659
+ * );
660
+ * ```
661
+ */
98
662
  export declare const except: MySqlCreateSetOperatorFn;
663
+ /**
664
+ * Adds `except all` set operator to the query.
665
+ *
666
+ * 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.
667
+ *
668
+ * See docs: {@link https://orm.drizzle.team/docs/set-operations#except-all}
669
+ *
670
+ * @example
671
+ *
672
+ * ```ts
673
+ * // Select all products that are ordered by regular customers but not by VIP customers
674
+ * import { exceptAll } from 'drizzle-orm/mysql-core'
675
+ *
676
+ * await exceptAll(
677
+ * db.select({
678
+ * productId: regularCustomerOrders.productId,
679
+ * quantityOrdered: regularCustomerOrders.quantityOrdered
680
+ * })
681
+ * .from(regularCustomerOrders),
682
+ * db.select({
683
+ * productId: vipCustomerOrders.productId,
684
+ * quantityOrdered: vipCustomerOrders.quantityOrdered
685
+ * })
686
+ * .from(vipCustomerOrders)
687
+ * );
688
+ * // or
689
+ * await db.select({
690
+ * productId: regularCustomerOrders.productId,
691
+ * quantityOrdered: regularCustomerOrders.quantityOrdered,
692
+ * })
693
+ * .from(regularCustomerOrders)
694
+ * .exceptAll(
695
+ * db.select({
696
+ * productId: vipCustomerOrders.productId,
697
+ * quantityOrdered: vipCustomerOrders.quantityOrdered,
698
+ * })
699
+ * .from(vipCustomerOrders)
700
+ * );
701
+ * ```
702
+ */
99
703
  export declare const exceptAll: MySqlCreateSetOperatorFn;