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