drizzle-orm 0.42.0 → 0.43.0-62ea5c4
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/gel-core/dialect.cjs +8 -23
- package/gel-core/dialect.cjs.map +1 -1
- package/gel-core/dialect.d.cts +1 -0
- package/gel-core/dialect.d.ts +1 -0
- package/gel-core/dialect.js +8 -23
- package/gel-core/dialect.js.map +1 -1
- package/gel-core/query-builders/select.cjs +80 -14
- package/gel-core/query-builders/select.cjs.map +1 -1
- package/gel-core/query-builders/select.d.cts +78 -13
- package/gel-core/query-builders/select.d.ts +78 -13
- package/gel-core/query-builders/select.js +80 -14
- package/gel-core/query-builders/select.js.map +1 -1
- package/gel-core/query-builders/select.types.cjs.map +1 -1
- package/gel-core/query-builders/select.types.d.cts +1 -1
- package/gel-core/query-builders/select.types.d.ts +1 -1
- package/mysql-core/dialect.cjs +5 -4
- package/mysql-core/dialect.cjs.map +1 -1
- package/mysql-core/dialect.js +5 -4
- package/mysql-core/dialect.js.map +1 -1
- package/mysql-core/query-builders/select.cjs +72 -34
- package/mysql-core/query-builders/select.cjs.map +1 -1
- package/mysql-core/query-builders/select.d.cts +66 -25
- package/mysql-core/query-builders/select.d.ts +66 -25
- package/mysql-core/query-builders/select.js +72 -34
- package/mysql-core/query-builders/select.js.map +1 -1
- package/mysql-core/query-builders/select.types.cjs.map +1 -1
- package/mysql-core/query-builders/select.types.d.cts +5 -4
- package/mysql-core/query-builders/select.types.d.ts +5 -4
- package/operations.cjs.map +1 -1
- package/operations.d.cts +5 -1
- package/operations.d.ts +5 -1
- package/package.json +1 -1
- package/pg-core/columns/text.cjs.map +1 -1
- package/pg-core/columns/text.d.cts +1 -2
- package/pg-core/columns/text.d.ts +1 -2
- package/pg-core/columns/text.js.map +1 -1
- package/pg-core/dialect.cjs +5 -4
- package/pg-core/dialect.cjs.map +1 -1
- package/pg-core/dialect.js +5 -4
- package/pg-core/dialect.js.map +1 -1
- package/pg-core/query-builders/select.cjs +80 -14
- package/pg-core/query-builders/select.cjs.map +1 -1
- package/pg-core/query-builders/select.d.cts +78 -13
- package/pg-core/query-builders/select.d.ts +78 -13
- package/pg-core/query-builders/select.js +80 -14
- package/pg-core/query-builders/select.js.map +1 -1
- package/pg-core/query-builders/select.types.cjs.map +1 -1
- package/pg-core/query-builders/select.types.d.cts +1 -1
- package/pg-core/query-builders/select.types.d.ts +1 -1
- package/query-builders/select.types.cjs.map +1 -1
- package/query-builders/select.types.d.cts +3 -1
- package/query-builders/select.types.d.ts +3 -1
- package/singlestore/driver.cjs +24 -2
- package/singlestore/driver.cjs.map +1 -1
- package/singlestore/driver.d.cts +3 -5
- package/singlestore/driver.d.ts +3 -5
- package/singlestore/driver.js +24 -2
- package/singlestore/driver.js.map +1 -1
- package/singlestore-core/dialect.cjs +5 -4
- package/singlestore-core/dialect.cjs.map +1 -1
- package/singlestore-core/dialect.js +5 -4
- package/singlestore-core/dialect.js.map +1 -1
- package/singlestore-core/query-builders/select.cjs +80 -14
- package/singlestore-core/query-builders/select.cjs.map +1 -1
- package/singlestore-core/query-builders/select.d.cts +78 -13
- package/singlestore-core/query-builders/select.d.ts +78 -13
- package/singlestore-core/query-builders/select.js +80 -14
- package/singlestore-core/query-builders/select.js.map +1 -1
- package/singlestore-core/query-builders/select.types.cjs.map +1 -1
- package/singlestore-core/query-builders/select.types.d.cts +1 -2
- package/singlestore-core/query-builders/select.types.d.ts +1 -2
- package/sqlite-core/dialect.cjs +3 -2
- package/sqlite-core/dialect.cjs.map +1 -1
- package/sqlite-core/dialect.js +3 -2
- package/sqlite-core/dialect.js.map +1 -1
- package/sqlite-core/query-builders/select.cjs +36 -8
- package/sqlite-core/query-builders/select.cjs.map +1 -1
- package/sqlite-core/query-builders/select.d.cts +40 -13
- package/sqlite-core/query-builders/select.d.ts +40 -13
- package/sqlite-core/query-builders/select.js +36 -8
- 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/select.types.d.cts +1 -1
- package/sqlite-core/query-builders/select.types.d.ts +1 -1
- package/version.cjs +1 -1
- package/version.d.cts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
|
@@ -13,7 +13,7 @@ import { Subquery } from "../../subquery.js";
|
|
|
13
13
|
import type { ValueOrArray } from "../../utils.js";
|
|
14
14
|
import type { IndexBuilder } from "../indexes.js";
|
|
15
15
|
import { MySqlViewBase } from "../view-base.js";
|
|
16
|
-
import type { CreateMySqlSelectFromBuilderMode, GetMySqlSetOperators, LockConfig, LockStrength, MySqlCreateSetOperatorFn,
|
|
16
|
+
import type { CreateMySqlSelectFromBuilderMode, GetMySqlSetOperators, LockConfig, LockStrength, MySqlCreateSetOperatorFn, MySqlSelectConfig, MySqlSelectDynamic, MySqlSelectHKT, MySqlSelectHKTBase, MySqlSelectPrepare, MySqlSelectWithout, MySqlSetOperatorExcludedMethods, MySqlSetOperatorWithResult, SelectedFields, SetOperatorRightSelect } from "./select.types.js";
|
|
17
17
|
export type IndexForHint = IndexBuilder | string;
|
|
18
18
|
export type IndexConfig = {
|
|
19
19
|
useIndex?: IndexForHint | IndexForHint[];
|
|
@@ -77,17 +77,18 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
77
77
|
*
|
|
78
78
|
* @param table the table to join.
|
|
79
79
|
* @param on the `on` clause.
|
|
80
|
+
* @param onIndex index hint.
|
|
80
81
|
*
|
|
81
82
|
* @example
|
|
82
83
|
*
|
|
83
84
|
* ```ts
|
|
84
85
|
* // Select all users and their pets
|
|
85
|
-
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
86
|
+
* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
|
|
86
87
|
* .from(users)
|
|
87
88
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
88
89
|
*
|
|
89
90
|
* // Select userId and petId
|
|
90
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
91
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
91
92
|
* userId: users.id,
|
|
92
93
|
* petId: pets.id,
|
|
93
94
|
* })
|
|
@@ -95,7 +96,7 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
95
96
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
96
97
|
*
|
|
97
98
|
* // Select userId and petId with use index hint
|
|
98
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
99
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
99
100
|
* userId: users.id,
|
|
100
101
|
* petId: pets.id,
|
|
101
102
|
* })
|
|
@@ -105,7 +106,20 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
105
106
|
* })
|
|
106
107
|
* ```
|
|
107
108
|
*/
|
|
108
|
-
leftJoin:
|
|
109
|
+
leftJoin: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>> | MySqlTable<import("../table.js").TableConfig> | MySqlViewBase<string, boolean, ColumnsSelection>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: SQL<unknown> | ((aliases: this["_"]["selection"]) => SQL | undefined) | undefined, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "left", TJoinedTable, TJoinedName>;
|
|
110
|
+
/**
|
|
111
|
+
* Executes a `left join lateral` operation by adding subquery to the current query.
|
|
112
|
+
*
|
|
113
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
114
|
+
*
|
|
115
|
+
* 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.
|
|
116
|
+
*
|
|
117
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}
|
|
118
|
+
*
|
|
119
|
+
* @param table the subquery to join.
|
|
120
|
+
* @param on the `on` clause.
|
|
121
|
+
*/
|
|
122
|
+
leftJoinLateral: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: SQL<unknown> | ((aliases: this["_"]["selection"]) => SQL | undefined) | undefined, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "left", TJoinedTable, TJoinedName>;
|
|
109
123
|
/**
|
|
110
124
|
* Executes a `right join` operation by adding another table to the current query.
|
|
111
125
|
*
|
|
@@ -115,17 +129,18 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
115
129
|
*
|
|
116
130
|
* @param table the table to join.
|
|
117
131
|
* @param on the `on` clause.
|
|
132
|
+
* @param onIndex index hint.
|
|
118
133
|
*
|
|
119
134
|
* @example
|
|
120
135
|
*
|
|
121
136
|
* ```ts
|
|
122
137
|
* // Select all users and their pets
|
|
123
|
-
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
138
|
+
* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
|
|
124
139
|
* .from(users)
|
|
125
140
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
126
141
|
*
|
|
127
142
|
* // Select userId and petId
|
|
128
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
143
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
|
|
129
144
|
* userId: users.id,
|
|
130
145
|
* petId: pets.id,
|
|
131
146
|
* })
|
|
@@ -133,7 +148,7 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
133
148
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
134
149
|
*
|
|
135
150
|
* // Select userId and petId with use index hint
|
|
136
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
151
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
137
152
|
* userId: users.id,
|
|
138
153
|
* petId: pets.id,
|
|
139
154
|
* })
|
|
@@ -143,7 +158,7 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
143
158
|
* })
|
|
144
159
|
* ```
|
|
145
160
|
*/
|
|
146
|
-
rightJoin:
|
|
161
|
+
rightJoin: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>> | MySqlTable<import("../table.js").TableConfig> | MySqlViewBase<string, boolean, ColumnsSelection>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: SQL<unknown> | ((aliases: this["_"]["selection"]) => SQL | undefined) | undefined, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "right", TJoinedTable, TJoinedName>;
|
|
147
162
|
/**
|
|
148
163
|
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
149
164
|
*
|
|
@@ -153,17 +168,18 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
153
168
|
*
|
|
154
169
|
* @param table the table to join.
|
|
155
170
|
* @param on the `on` clause.
|
|
171
|
+
* @param onIndex index hint.
|
|
156
172
|
*
|
|
157
173
|
* @example
|
|
158
174
|
*
|
|
159
175
|
* ```ts
|
|
160
176
|
* // Select all users and their pets
|
|
161
|
-
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
177
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
162
178
|
* .from(users)
|
|
163
179
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
164
180
|
*
|
|
165
181
|
* // Select userId and petId
|
|
166
|
-
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
182
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
167
183
|
* userId: users.id,
|
|
168
184
|
* petId: pets.id,
|
|
169
185
|
* })
|
|
@@ -171,7 +187,7 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
171
187
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
172
188
|
*
|
|
173
189
|
* // Select userId and petId with use index hint
|
|
174
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
190
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
175
191
|
* userId: users.id,
|
|
176
192
|
* petId: pets.id,
|
|
177
193
|
* })
|
|
@@ -181,45 +197,70 @@ export declare abstract class MySqlSelectQueryBuilderBase<THKT extends MySqlSele
|
|
|
181
197
|
* })
|
|
182
198
|
* ```
|
|
183
199
|
*/
|
|
184
|
-
innerJoin:
|
|
200
|
+
innerJoin: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>> | MySqlTable<import("../table.js").TableConfig> | MySqlViewBase<string, boolean, ColumnsSelection>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: SQL<unknown> | ((aliases: this["_"]["selection"]) => SQL | undefined) | undefined, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "inner", TJoinedTable, TJoinedName>;
|
|
185
201
|
/**
|
|
186
|
-
* Executes
|
|
202
|
+
* Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.
|
|
187
203
|
*
|
|
188
|
-
*
|
|
204
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
189
205
|
*
|
|
190
|
-
*
|
|
206
|
+
* 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.
|
|
191
207
|
*
|
|
192
|
-
*
|
|
208
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}
|
|
209
|
+
*
|
|
210
|
+
* @param table the subquery to join.
|
|
193
211
|
* @param on the `on` clause.
|
|
212
|
+
*/
|
|
213
|
+
innerJoinLateral: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: SQL<unknown> | ((aliases: this["_"]["selection"]) => SQL | undefined) | undefined, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "inner", TJoinedTable, TJoinedName>;
|
|
214
|
+
/**
|
|
215
|
+
* Executes a `cross join` operation by combining rows from two tables into a new table.
|
|
216
|
+
*
|
|
217
|
+
* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
|
|
218
|
+
*
|
|
219
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
|
|
220
|
+
*
|
|
221
|
+
* @param table the table to join.
|
|
222
|
+
* @param onIndex index hint.
|
|
194
223
|
*
|
|
195
224
|
* @example
|
|
196
225
|
*
|
|
197
226
|
* ```ts
|
|
198
|
-
* // Select all users
|
|
199
|
-
* const usersWithPets: { user: User
|
|
227
|
+
* // Select all users, each user with every pet
|
|
228
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
200
229
|
* .from(users)
|
|
201
|
-
* .
|
|
230
|
+
* .crossJoin(pets)
|
|
202
231
|
*
|
|
203
232
|
* // Select userId and petId
|
|
204
|
-
* const usersIdsAndPetIds: { userId: number
|
|
233
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
205
234
|
* userId: users.id,
|
|
206
235
|
* petId: pets.id,
|
|
207
236
|
* })
|
|
208
237
|
* .from(users)
|
|
209
|
-
* .
|
|
238
|
+
* .crossJoin(pets)
|
|
210
239
|
*
|
|
211
240
|
* // Select userId and petId with use index hint
|
|
212
|
-
* const usersIdsAndPetIds: { userId: number; petId: number
|
|
241
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
213
242
|
* userId: users.id,
|
|
214
243
|
* petId: pets.id,
|
|
215
244
|
* })
|
|
216
245
|
* .from(users)
|
|
217
|
-
* .
|
|
246
|
+
* .crossJoin(pets, {
|
|
218
247
|
* useIndex: ['pets_owner_id_index']
|
|
219
248
|
* })
|
|
220
249
|
* ```
|
|
221
250
|
*/
|
|
222
|
-
|
|
251
|
+
crossJoin: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>> | MySqlTable<import("../table.js").TableConfig> | MySqlViewBase<string, boolean, ColumnsSelection>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "cross", TJoinedTable, TJoinedName>;
|
|
252
|
+
/**
|
|
253
|
+
* Executes a `cross join lateral` operation by combining rows from two queries into a new table.
|
|
254
|
+
*
|
|
255
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
256
|
+
*
|
|
257
|
+
* Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.
|
|
258
|
+
*
|
|
259
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}
|
|
260
|
+
*
|
|
261
|
+
* @param table the query to join.
|
|
262
|
+
*/
|
|
263
|
+
crossJoinLateral: <TJoinedTable extends SQL<unknown> | Subquery<string, Record<string, unknown>>, TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, onIndex?: (TJoinedTable extends MySqlTable<import("../table.js").TableConfig> ? IndexConfig : "Index hint configuration is allowed only for MySqlTable and not for subqueries or views") | undefined) => import("./select.types.js").MySqlJoin<this, TDynamic, "cross", TJoinedTable, TJoinedName>;
|
|
223
264
|
private createSetOperator;
|
|
224
265
|
/**
|
|
225
266
|
* Adds `union` set operator to the query.
|
|
@@ -103,8 +103,11 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
103
103
|
this.tableName = getTableLikeName(table);
|
|
104
104
|
this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
|
|
105
105
|
}
|
|
106
|
-
createJoin(joinType) {
|
|
107
|
-
return (table,
|
|
106
|
+
createJoin(joinType, lateral) {
|
|
107
|
+
return (table, a, b) => {
|
|
108
|
+
const isCrossJoin = joinType === "cross";
|
|
109
|
+
let on = isCrossJoin ? void 0 : a;
|
|
110
|
+
const onIndex = isCrossJoin ? a : b;
|
|
108
111
|
const baseTableName = this.tableName;
|
|
109
112
|
const tableName = getTableLikeName(table);
|
|
110
113
|
if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) {
|
|
@@ -146,7 +149,7 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
146
149
|
ignoreIndex = convertIndexToString(toArray(onIndex.ignoreIndex));
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
|
-
this.config.joins.push({ on, table, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex });
|
|
152
|
+
this.config.joins.push({ on, table, joinType, alias: tableName, useIndex, forceIndex, ignoreIndex, lateral });
|
|
150
153
|
if (typeof tableName === "string") {
|
|
151
154
|
switch (joinType) {
|
|
152
155
|
case "left": {
|
|
@@ -160,17 +163,11 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
160
163
|
this.joinsNotNullableMap[tableName] = true;
|
|
161
164
|
break;
|
|
162
165
|
}
|
|
166
|
+
case "cross":
|
|
163
167
|
case "inner": {
|
|
164
168
|
this.joinsNotNullableMap[tableName] = true;
|
|
165
169
|
break;
|
|
166
170
|
}
|
|
167
|
-
case "full": {
|
|
168
|
-
this.joinsNotNullableMap = Object.fromEntries(
|
|
169
|
-
Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false])
|
|
170
|
-
);
|
|
171
|
-
this.joinsNotNullableMap[tableName] = false;
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
171
|
}
|
|
175
172
|
}
|
|
176
173
|
return this;
|
|
@@ -185,17 +182,18 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
185
182
|
*
|
|
186
183
|
* @param table the table to join.
|
|
187
184
|
* @param on the `on` clause.
|
|
185
|
+
* @param onIndex index hint.
|
|
188
186
|
*
|
|
189
187
|
* @example
|
|
190
188
|
*
|
|
191
189
|
* ```ts
|
|
192
190
|
* // Select all users and their pets
|
|
193
|
-
* const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
|
|
191
|
+
* const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
|
|
194
192
|
* .from(users)
|
|
195
193
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
196
194
|
*
|
|
197
195
|
* // Select userId and petId
|
|
198
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
196
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
199
197
|
* userId: users.id,
|
|
200
198
|
* petId: pets.id,
|
|
201
199
|
* })
|
|
@@ -203,7 +201,7 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
203
201
|
* .leftJoin(pets, eq(users.id, pets.ownerId))
|
|
204
202
|
*
|
|
205
203
|
* // Select userId and petId with use index hint
|
|
206
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
204
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
207
205
|
* userId: users.id,
|
|
208
206
|
* petId: pets.id,
|
|
209
207
|
* })
|
|
@@ -213,7 +211,20 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
213
211
|
* })
|
|
214
212
|
* ```
|
|
215
213
|
*/
|
|
216
|
-
leftJoin = this.createJoin("left");
|
|
214
|
+
leftJoin = this.createJoin("left", false);
|
|
215
|
+
/**
|
|
216
|
+
* Executes a `left join lateral` operation by adding subquery to the current query.
|
|
217
|
+
*
|
|
218
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
219
|
+
*
|
|
220
|
+
* 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.
|
|
221
|
+
*
|
|
222
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}
|
|
223
|
+
*
|
|
224
|
+
* @param table the subquery to join.
|
|
225
|
+
* @param on the `on` clause.
|
|
226
|
+
*/
|
|
227
|
+
leftJoinLateral = this.createJoin("left", true);
|
|
217
228
|
/**
|
|
218
229
|
* Executes a `right join` operation by adding another table to the current query.
|
|
219
230
|
*
|
|
@@ -223,17 +234,18 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
223
234
|
*
|
|
224
235
|
* @param table the table to join.
|
|
225
236
|
* @param on the `on` clause.
|
|
237
|
+
* @param onIndex index hint.
|
|
226
238
|
*
|
|
227
239
|
* @example
|
|
228
240
|
*
|
|
229
241
|
* ```ts
|
|
230
242
|
* // Select all users and their pets
|
|
231
|
-
* const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
|
|
243
|
+
* const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
|
|
232
244
|
* .from(users)
|
|
233
245
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
234
246
|
*
|
|
235
247
|
* // Select userId and petId
|
|
236
|
-
* const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
|
|
248
|
+
* const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
|
|
237
249
|
* userId: users.id,
|
|
238
250
|
* petId: pets.id,
|
|
239
251
|
* })
|
|
@@ -241,7 +253,7 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
241
253
|
* .rightJoin(pets, eq(users.id, pets.ownerId))
|
|
242
254
|
*
|
|
243
255
|
* // Select userId and petId with use index hint
|
|
244
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
256
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
245
257
|
* userId: users.id,
|
|
246
258
|
* petId: pets.id,
|
|
247
259
|
* })
|
|
@@ -251,7 +263,7 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
251
263
|
* })
|
|
252
264
|
* ```
|
|
253
265
|
*/
|
|
254
|
-
rightJoin = this.createJoin("right");
|
|
266
|
+
rightJoin = this.createJoin("right", false);
|
|
255
267
|
/**
|
|
256
268
|
* Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
|
|
257
269
|
*
|
|
@@ -261,17 +273,18 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
261
273
|
*
|
|
262
274
|
* @param table the table to join.
|
|
263
275
|
* @param on the `on` clause.
|
|
276
|
+
* @param onIndex index hint.
|
|
264
277
|
*
|
|
265
278
|
* @example
|
|
266
279
|
*
|
|
267
280
|
* ```ts
|
|
268
281
|
* // Select all users and their pets
|
|
269
|
-
* const usersWithPets: { user: User; pets: Pet }[] = await db.select()
|
|
282
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
270
283
|
* .from(users)
|
|
271
284
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
272
285
|
*
|
|
273
286
|
* // Select userId and petId
|
|
274
|
-
* const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
|
|
287
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
275
288
|
* userId: users.id,
|
|
276
289
|
* petId: pets.id,
|
|
277
290
|
* })
|
|
@@ -279,7 +292,7 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
279
292
|
* .innerJoin(pets, eq(users.id, pets.ownerId))
|
|
280
293
|
*
|
|
281
294
|
* // Select userId and petId with use index hint
|
|
282
|
-
* const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
|
|
295
|
+
* const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
|
|
283
296
|
* userId: users.id,
|
|
284
297
|
* petId: pets.id,
|
|
285
298
|
* })
|
|
@@ -289,45 +302,70 @@ class MySqlSelectQueryBuilderBase extends TypedQueryBuilder {
|
|
|
289
302
|
* })
|
|
290
303
|
* ```
|
|
291
304
|
*/
|
|
292
|
-
innerJoin = this.createJoin("inner");
|
|
305
|
+
innerJoin = this.createJoin("inner", false);
|
|
293
306
|
/**
|
|
294
|
-
* Executes
|
|
307
|
+
* Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.
|
|
295
308
|
*
|
|
296
|
-
*
|
|
309
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
297
310
|
*
|
|
298
|
-
*
|
|
311
|
+
* 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.
|
|
299
312
|
*
|
|
300
|
-
*
|
|
313
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}
|
|
314
|
+
*
|
|
315
|
+
* @param table the subquery to join.
|
|
301
316
|
* @param on the `on` clause.
|
|
317
|
+
*/
|
|
318
|
+
innerJoinLateral = this.createJoin("inner", true);
|
|
319
|
+
/**
|
|
320
|
+
* Executes a `cross join` operation by combining rows from two tables into a new table.
|
|
321
|
+
*
|
|
322
|
+
* Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
|
|
323
|
+
*
|
|
324
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
|
|
325
|
+
*
|
|
326
|
+
* @param table the table to join.
|
|
327
|
+
* @param onIndex index hint.
|
|
302
328
|
*
|
|
303
329
|
* @example
|
|
304
330
|
*
|
|
305
331
|
* ```ts
|
|
306
|
-
* // Select all users
|
|
307
|
-
* const usersWithPets: { user: User
|
|
332
|
+
* // Select all users, each user with every pet
|
|
333
|
+
* const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
|
|
308
334
|
* .from(users)
|
|
309
|
-
* .
|
|
335
|
+
* .crossJoin(pets)
|
|
310
336
|
*
|
|
311
337
|
* // Select userId and petId
|
|
312
|
-
* const usersIdsAndPetIds: { userId: number
|
|
338
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
313
339
|
* userId: users.id,
|
|
314
340
|
* petId: pets.id,
|
|
315
341
|
* })
|
|
316
342
|
* .from(users)
|
|
317
|
-
* .
|
|
343
|
+
* .crossJoin(pets)
|
|
318
344
|
*
|
|
319
345
|
* // Select userId and petId with use index hint
|
|
320
|
-
* const usersIdsAndPetIds: { userId: number; petId: number
|
|
346
|
+
* const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
|
|
321
347
|
* userId: users.id,
|
|
322
348
|
* petId: pets.id,
|
|
323
349
|
* })
|
|
324
350
|
* .from(users)
|
|
325
|
-
* .
|
|
351
|
+
* .crossJoin(pets, {
|
|
326
352
|
* useIndex: ['pets_owner_id_index']
|
|
327
353
|
* })
|
|
328
354
|
* ```
|
|
329
355
|
*/
|
|
330
|
-
|
|
356
|
+
crossJoin = this.createJoin("cross", false);
|
|
357
|
+
/**
|
|
358
|
+
* Executes a `cross join lateral` operation by combining rows from two queries into a new table.
|
|
359
|
+
*
|
|
360
|
+
* A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
|
|
361
|
+
*
|
|
362
|
+
* Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.
|
|
363
|
+
*
|
|
364
|
+
* See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}
|
|
365
|
+
*
|
|
366
|
+
* @param table the query to join.
|
|
367
|
+
*/
|
|
368
|
+
crossJoinLateral = this.createJoin("cross", true);
|
|
331
369
|
createSetOperator(type, isAll) {
|
|
332
370
|
return (rightSelection) => {
|
|
333
371
|
const rightSelect = typeof rightSelection === "function" ? rightSelection(getMySqlSetOperators()) : rightSelection;
|