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.
Files changed (88) hide show
  1. package/gel-core/dialect.cjs +8 -23
  2. package/gel-core/dialect.cjs.map +1 -1
  3. package/gel-core/dialect.d.cts +1 -0
  4. package/gel-core/dialect.d.ts +1 -0
  5. package/gel-core/dialect.js +8 -23
  6. package/gel-core/dialect.js.map +1 -1
  7. package/gel-core/query-builders/select.cjs +80 -14
  8. package/gel-core/query-builders/select.cjs.map +1 -1
  9. package/gel-core/query-builders/select.d.cts +78 -13
  10. package/gel-core/query-builders/select.d.ts +78 -13
  11. package/gel-core/query-builders/select.js +80 -14
  12. package/gel-core/query-builders/select.js.map +1 -1
  13. package/gel-core/query-builders/select.types.cjs.map +1 -1
  14. package/gel-core/query-builders/select.types.d.cts +1 -1
  15. package/gel-core/query-builders/select.types.d.ts +1 -1
  16. package/mysql-core/dialect.cjs +5 -4
  17. package/mysql-core/dialect.cjs.map +1 -1
  18. package/mysql-core/dialect.js +5 -4
  19. package/mysql-core/dialect.js.map +1 -1
  20. package/mysql-core/query-builders/select.cjs +72 -34
  21. package/mysql-core/query-builders/select.cjs.map +1 -1
  22. package/mysql-core/query-builders/select.d.cts +66 -25
  23. package/mysql-core/query-builders/select.d.ts +66 -25
  24. package/mysql-core/query-builders/select.js +72 -34
  25. package/mysql-core/query-builders/select.js.map +1 -1
  26. package/mysql-core/query-builders/select.types.cjs.map +1 -1
  27. package/mysql-core/query-builders/select.types.d.cts +5 -4
  28. package/mysql-core/query-builders/select.types.d.ts +5 -4
  29. package/operations.cjs.map +1 -1
  30. package/operations.d.cts +5 -1
  31. package/operations.d.ts +5 -1
  32. package/package.json +1 -1
  33. package/pg-core/columns/text.cjs.map +1 -1
  34. package/pg-core/columns/text.d.cts +1 -2
  35. package/pg-core/columns/text.d.ts +1 -2
  36. package/pg-core/columns/text.js.map +1 -1
  37. package/pg-core/dialect.cjs +5 -4
  38. package/pg-core/dialect.cjs.map +1 -1
  39. package/pg-core/dialect.js +5 -4
  40. package/pg-core/dialect.js.map +1 -1
  41. package/pg-core/query-builders/select.cjs +80 -14
  42. package/pg-core/query-builders/select.cjs.map +1 -1
  43. package/pg-core/query-builders/select.d.cts +78 -13
  44. package/pg-core/query-builders/select.d.ts +78 -13
  45. package/pg-core/query-builders/select.js +80 -14
  46. package/pg-core/query-builders/select.js.map +1 -1
  47. package/pg-core/query-builders/select.types.cjs.map +1 -1
  48. package/pg-core/query-builders/select.types.d.cts +1 -1
  49. package/pg-core/query-builders/select.types.d.ts +1 -1
  50. package/query-builders/select.types.cjs.map +1 -1
  51. package/query-builders/select.types.d.cts +3 -1
  52. package/query-builders/select.types.d.ts +3 -1
  53. package/singlestore/driver.cjs +24 -2
  54. package/singlestore/driver.cjs.map +1 -1
  55. package/singlestore/driver.d.cts +3 -5
  56. package/singlestore/driver.d.ts +3 -5
  57. package/singlestore/driver.js +24 -2
  58. package/singlestore/driver.js.map +1 -1
  59. package/singlestore-core/dialect.cjs +5 -4
  60. package/singlestore-core/dialect.cjs.map +1 -1
  61. package/singlestore-core/dialect.js +5 -4
  62. package/singlestore-core/dialect.js.map +1 -1
  63. package/singlestore-core/query-builders/select.cjs +80 -14
  64. package/singlestore-core/query-builders/select.cjs.map +1 -1
  65. package/singlestore-core/query-builders/select.d.cts +78 -13
  66. package/singlestore-core/query-builders/select.d.ts +78 -13
  67. package/singlestore-core/query-builders/select.js +80 -14
  68. package/singlestore-core/query-builders/select.js.map +1 -1
  69. package/singlestore-core/query-builders/select.types.cjs.map +1 -1
  70. package/singlestore-core/query-builders/select.types.d.cts +1 -2
  71. package/singlestore-core/query-builders/select.types.d.ts +1 -2
  72. package/sqlite-core/dialect.cjs +3 -2
  73. package/sqlite-core/dialect.cjs.map +1 -1
  74. package/sqlite-core/dialect.js +3 -2
  75. package/sqlite-core/dialect.js.map +1 -1
  76. package/sqlite-core/query-builders/select.cjs +36 -8
  77. package/sqlite-core/query-builders/select.cjs.map +1 -1
  78. package/sqlite-core/query-builders/select.d.cts +40 -13
  79. package/sqlite-core/query-builders/select.d.ts +40 -13
  80. package/sqlite-core/query-builders/select.js +36 -8
  81. package/sqlite-core/query-builders/select.js.map +1 -1
  82. package/sqlite-core/query-builders/select.types.cjs.map +1 -1
  83. package/sqlite-core/query-builders/select.types.d.cts +1 -1
  84. package/sqlite-core/query-builders/select.types.d.ts +1 -1
  85. package/version.cjs +1 -1
  86. package/version.d.cts +1 -1
  87. package/version.d.ts +1 -1
  88. package/version.js +1 -1
@@ -83,7 +83,7 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
83
83
  this.tableName = getTableLikeName(table);
84
84
  this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {};
85
85
  }
86
- createJoin(joinType) {
86
+ createJoin(joinType, lateral) {
87
87
  return (table, on) => {
88
88
  const baseTableName = this.tableName;
89
89
  const tableName = getTableLikeName(table);
@@ -112,7 +112,7 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
112
112
  if (!this.config.joins) {
113
113
  this.config.joins = [];
114
114
  }
115
- this.config.joins.push({ on, table, joinType, alias: tableName });
115
+ this.config.joins.push({ on, table, joinType, alias: tableName, lateral });
116
116
  if (typeof tableName === "string") {
117
117
  switch (joinType) {
118
118
  case "left": {
@@ -126,6 +126,7 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
126
126
  this.joinsNotNullableMap[tableName] = true;
127
127
  break;
128
128
  }
129
+ case "cross":
129
130
  case "inner": {
130
131
  this.joinsNotNullableMap[tableName] = true;
131
132
  break;
@@ -156,12 +157,12 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
156
157
  *
157
158
  * ```ts
158
159
  * // Select all users and their pets
159
- * const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()
160
+ * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()
160
161
  * .from(users)
161
162
  * .leftJoin(pets, eq(users.id, pets.ownerId))
162
163
  *
163
164
  * // Select userId and petId
164
- * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({
165
+ * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({
165
166
  * userId: users.id,
166
167
  * petId: pets.id,
167
168
  * })
@@ -169,7 +170,20 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
169
170
  * .leftJoin(pets, eq(users.id, pets.ownerId))
170
171
  * ```
171
172
  */
172
- leftJoin = this.createJoin("left");
173
+ leftJoin = this.createJoin("left", false);
174
+ /**
175
+ * Executes a `left join lateral` operation by adding subquery to the current query.
176
+ *
177
+ * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
178
+ *
179
+ * 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.
180
+ *
181
+ * See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}
182
+ *
183
+ * @param table the subquery to join.
184
+ * @param on the `on` clause.
185
+ */
186
+ leftJoinLateral = this.createJoin("left", true);
173
187
  /**
174
188
  * Executes a `right join` operation by adding another table to the current query.
175
189
  *
@@ -184,12 +198,12 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
184
198
  *
185
199
  * ```ts
186
200
  * // Select all users and their pets
187
- * const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()
201
+ * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()
188
202
  * .from(users)
189
203
  * .rightJoin(pets, eq(users.id, pets.ownerId))
190
204
  *
191
205
  * // Select userId and petId
192
- * const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({
206
+ * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({
193
207
  * userId: users.id,
194
208
  * petId: pets.id,
195
209
  * })
@@ -197,7 +211,7 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
197
211
  * .rightJoin(pets, eq(users.id, pets.ownerId))
198
212
  * ```
199
213
  */
200
- rightJoin = this.createJoin("right");
214
+ rightJoin = this.createJoin("right", false);
201
215
  /**
202
216
  * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.
203
217
  *
@@ -212,12 +226,12 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
212
226
  *
213
227
  * ```ts
214
228
  * // Select all users and their pets
215
- * const usersWithPets: { user: User; pets: Pet }[] = await db.select()
229
+ * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
216
230
  * .from(users)
217
231
  * .innerJoin(pets, eq(users.id, pets.ownerId))
218
232
  *
219
233
  * // Select userId and petId
220
- * const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({
234
+ * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
221
235
  * userId: users.id,
222
236
  * petId: pets.id,
223
237
  * })
@@ -225,7 +239,20 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
225
239
  * .innerJoin(pets, eq(users.id, pets.ownerId))
226
240
  * ```
227
241
  */
228
- innerJoin = this.createJoin("inner");
242
+ innerJoin = this.createJoin("inner", false);
243
+ /**
244
+ * Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.
245
+ *
246
+ * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
247
+ *
248
+ * 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.
249
+ *
250
+ * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}
251
+ *
252
+ * @param table the subquery to join.
253
+ * @param on the `on` clause.
254
+ */
255
+ innerJoinLateral = this.createJoin("inner", true);
229
256
  /**
230
257
  * Executes a `full join` operation by combining rows from two tables into a new table.
231
258
  *
@@ -240,12 +267,12 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
240
267
  *
241
268
  * ```ts
242
269
  * // Select all users and their pets
243
- * const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()
270
+ * const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()
244
271
  * .from(users)
245
272
  * .fullJoin(pets, eq(users.id, pets.ownerId))
246
273
  *
247
274
  * // Select userId and petId
248
- * const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({
275
+ * const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({
249
276
  * userId: users.id,
250
277
  * petId: pets.id,
251
278
  * })
@@ -253,7 +280,46 @@ class SingleStoreSelectQueryBuilderBase extends TypedQueryBuilder {
253
280
  * .fullJoin(pets, eq(users.id, pets.ownerId))
254
281
  * ```
255
282
  */
256
- fullJoin = this.createJoin("full");
283
+ fullJoin = this.createJoin("full", false);
284
+ /**
285
+ * Executes a `cross join` operation by combining rows from two tables into a new table.
286
+ *
287
+ * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.
288
+ *
289
+ * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}
290
+ *
291
+ * @param table the table to join.
292
+ *
293
+ * @example
294
+ *
295
+ * ```ts
296
+ * // Select all users, each user with every pet
297
+ * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()
298
+ * .from(users)
299
+ * .crossJoin(pets)
300
+ *
301
+ * // Select userId and petId
302
+ * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({
303
+ * userId: users.id,
304
+ * petId: pets.id,
305
+ * })
306
+ * .from(users)
307
+ * .crossJoin(pets)
308
+ * ```
309
+ */
310
+ crossJoin = this.createJoin("cross", false);
311
+ /**
312
+ * Executes a `cross join lateral` operation by combining rows from two queries into a new table.
313
+ *
314
+ * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.
315
+ *
316
+ * Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.
317
+ *
318
+ * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}
319
+ *
320
+ * @param table the query to join.
321
+ */
322
+ crossJoinLateral = this.createJoin("cross", true);
257
323
  createSetOperator(type, isAll) {
258
324
  return (rightSelection) => {
259
325
  const rightSelect = typeof rightSelection === "function" ? rightSelection(getSingleStoreSetOperators()) : rightSelection;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/singlestore-core/query-builders/select.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tGetSelectTableSelection,\n\tJoinNullability,\n\tJoinType,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreColumn } from '~/singlestore-core/columns/index.ts';\nimport type { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStorePreparedQueryConfig,\n\tSingleStoreSession,\n} from '~/singlestore-core/session.ts';\nimport type { SubqueryWithSelection } from '~/singlestore-core/subquery.ts';\nimport type { SingleStoreTable } from '~/singlestore-core/table.ts';\nimport type { ColumnsSelection, Query } from '~/sql/sql.ts';\nimport { SQL } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport {\n\tapplyMixins,\n\tgetTableColumns,\n\tgetTableLikeName,\n\thaveSameKeys,\n\torderSelectedFields,\n\ttype ValueOrArray,\n} from '~/utils.ts';\nimport type {\n\tAnySingleStoreSelect,\n\tCreateSingleStoreSelectFromBuilderMode,\n\tGetSingleStoreSetOperators,\n\tLockConfig,\n\tLockStrength,\n\tSelectedFields,\n\tSetOperatorRightSelect,\n\tSingleStoreCreateSetOperatorFn,\n\tSingleStoreJoinFn,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectDynamic,\n\tSingleStoreSelectHKT,\n\tSingleStoreSelectHKTBase,\n\tSingleStoreSelectPrepare,\n\tSingleStoreSelectWithout,\n\tSingleStoreSetOperatorExcludedMethods,\n\tSingleStoreSetOperatorWithResult,\n} from './select.types.ts';\n\nexport class SingleStoreSelectBuilder<\n\tTSelection extends SelectedFields | undefined,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTBuilderMode extends 'db' | 'qb' = 'db',\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreSelectBuilder';\n\n\tprivate fields: TSelection;\n\tprivate session: SingleStoreSession | undefined;\n\tprivate dialect: SingleStoreDialect;\n\tprivate withList: Subquery[] = [];\n\tprivate distinct: boolean | undefined;\n\n\tconstructor(\n\t\tconfig: {\n\t\t\tfields: TSelection;\n\t\t\tsession: SingleStoreSession | undefined;\n\t\t\tdialect: SingleStoreDialect;\n\t\t\twithList?: Subquery[];\n\t\t\tdistinct?: boolean;\n\t\t},\n\t) {\n\t\tthis.fields = config.fields;\n\t\tthis.session = config.session;\n\t\tthis.dialect = config.dialect;\n\t\tif (config.withList) {\n\t\t\tthis.withList = config.withList;\n\t\t}\n\t\tthis.distinct = config.distinct;\n\t}\n\n\tfrom<TFrom extends SingleStoreTable | Subquery | SQL>( // | SingleStoreViewBase\n\t\tsource: TFrom,\n\t): CreateSingleStoreSelectFromBuilderMode<\n\t\tTBuilderMode,\n\t\tGetSelectTableName<TFrom>,\n\t\tTSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,\n\t\tTSelection extends undefined ? 'single' : 'partial',\n\t\tTPreparedQueryHKT\n\t> {\n\t\tconst isPartialSelect = !!this.fields;\n\n\t\tlet fields: SelectedFields;\n\t\tif (this.fields) {\n\t\t\tfields = this.fields;\n\t\t} else if (is(source, Subquery)) {\n\t\t\t// This is required to use the proxy handler to get the correct field values from the subquery\n\t\t\tfields = Object.fromEntries(\n\t\t\t\tObject.keys(source._.selectedFields).map((\n\t\t\t\t\tkey,\n\t\t\t\t) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),\n\t\t\t);\n\t\t\t/* } else if (is(source, SingleStoreViewBase)) {\n\t\t\tfields = source[ViewBaseConfig].selectedFields as SelectedFields; */\n\t\t} else if (is(source, SQL)) {\n\t\t\tfields = {};\n\t\t} else {\n\t\t\tfields = getTableColumns<SingleStoreTable>(source);\n\t\t}\n\n\t\treturn new SingleStoreSelectBase(\n\t\t\t{\n\t\t\t\ttable: source,\n\t\t\t\tfields,\n\t\t\t\tisPartialSelect,\n\t\t\t\tsession: this.session,\n\t\t\t\tdialect: this.dialect,\n\t\t\t\twithList: this.withList,\n\t\t\t\tdistinct: this.distinct,\n\t\t\t},\n\t\t) as any;\n\t}\n}\n\nexport abstract class SingleStoreSelectQueryBuilderBase<\n\tTHKT extends SingleStoreSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends TypedQueryBuilder<TSelectedFields, TResult> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreSelectQueryBuilder';\n\n\toverride readonly _: {\n\t\treadonly hkt: THKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n\n\tprotected config: SingleStoreSelectConfig;\n\tprotected joinsNotNullableMap: Record<string, boolean>;\n\tprivate tableName: string | undefined;\n\tprivate isPartialSelect: boolean;\n\t/** @internal */\n\treadonly session: SingleStoreSession | undefined;\n\tprotected dialect: SingleStoreDialect;\n\n\tconstructor(\n\t\t{ table, fields, isPartialSelect, session, dialect, withList, distinct }: {\n\t\t\ttable: SingleStoreSelectConfig['table'];\n\t\t\tfields: SingleStoreSelectConfig['fields'];\n\t\t\tisPartialSelect: boolean;\n\t\t\tsession: SingleStoreSession | undefined;\n\t\t\tdialect: SingleStoreDialect;\n\t\t\twithList: Subquery[];\n\t\t\tdistinct: boolean | undefined;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.config = {\n\t\t\twithList,\n\t\t\ttable,\n\t\t\tfields: { ...fields },\n\t\t\tdistinct,\n\t\t\tsetOperators: [],\n\t\t};\n\t\tthis.isPartialSelect = isPartialSelect;\n\t\tthis.session = session;\n\t\tthis.dialect = dialect;\n\t\tthis._ = {\n\t\t\tselectedFields: fields as TSelectedFields,\n\t\t} as this['_'];\n\t\tthis.tableName = getTableLikeName(table);\n\t\tthis.joinsNotNullableMap = typeof this.tableName === 'string' ? { [this.tableName]: true } : {};\n\t}\n\n\tprivate createJoin<TJoinType extends JoinType>(\n\t\tjoinType: TJoinType,\n\t): SingleStoreJoinFn<this, TDynamic, TJoinType> {\n\t\treturn (\n\t\t\ttable: SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\t\t\ton: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,\n\t\t) => {\n\t\t\tconst baseTableName = this.tableName;\n\t\t\tconst tableName = getTableLikeName(table);\n\n\t\t\tif (typeof tableName === 'string' && this.config.joins?.some((join) => join.alias === tableName)) {\n\t\t\t\tthrow new Error(`Alias \"${tableName}\" is already used in this query`);\n\t\t\t}\n\n\t\t\tif (!this.isPartialSelect) {\n\t\t\t\t// If this is the first join and this is not a partial select and we're not selecting from raw SQL, \"move\" the fields from the main table to the nested object\n\t\t\t\tif (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === 'string') {\n\t\t\t\t\tthis.config.fields = {\n\t\t\t\t\t\t[baseTableName]: this.config.fields,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (typeof tableName === 'string' && !is(table, SQL)) {\n\t\t\t\t\tconst selection = is(table, Subquery)\n\t\t\t\t\t\t? table._.selectedFields\n\t\t\t\t\t\t/* : is(table, View)\n\t\t\t\t\t\t? table[ViewBaseConfig].selectedFields */\n\t\t\t\t\t\t: table[Table.Symbol.Columns];\n\t\t\t\t\tthis.config.fields[tableName] = selection;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof on === 'function') {\n\t\t\t\ton = on(\n\t\t\t\t\tnew Proxy(\n\t\t\t\t\t\tthis.config.fields,\n\t\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t\t) as TSelection,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!this.config.joins) {\n\t\t\t\tthis.config.joins = [];\n\t\t\t}\n\n\t\t\tthis.config.joins.push({ on, table, joinType, alias: tableName });\n\n\t\t\tif (typeof tableName === 'string') {\n\t\t\t\tswitch (joinType) {\n\t\t\t\t\tcase 'left': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'right': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'inner': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'full': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Executes a `left join` operation by adding another table to the current query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet | null }[] = await db.select()\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tleftJoin = this.createJoin('left');\n\n\t/**\n\t * Executes a `right join` operation by adding another table to the current query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet }[] = await db.select()\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\trightJoin = this.createJoin('right');\n\n\t/**\n\t * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet }[] = await db.select()\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tinnerJoin = this.createJoin('inner');\n\n\t/**\n\t * Executes a `full join` operation by combining rows from two tables into a new table.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select()\n\t * .from(users)\n\t * .fullJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .fullJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tfullJoin = this.createJoin('full');\n\n\tprivate createSetOperator(\n\t\ttype: SetOperator,\n\t\tisAll: boolean,\n\t): <TValue extends SingleStoreSetOperatorWithResult<TResult>>(\n\t\trightSelection:\n\t\t\t| ((setOperators: GetSingleStoreSetOperators) => SetOperatorRightSelect<TValue, TResult>)\n\t\t\t| SetOperatorRightSelect<TValue, TResult>,\n\t) => SingleStoreSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tSingleStoreSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\treturn (rightSelection) => {\n\t\t\tconst rightSelect = (typeof rightSelection === 'function'\n\t\t\t\t? rightSelection(getSingleStoreSetOperators())\n\t\t\t\t: rightSelection) as TypedQueryBuilder<\n\t\t\t\t\tany,\n\t\t\t\t\tTResult\n\t\t\t\t>;\n\n\t\t\tif (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.config.setOperators.push({ type, isAll, rightSelect });\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Adds `union` set operator to the query.\n\t *\n\t * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all unique names from customers and users tables\n\t * await db.select({ name: users.name })\n\t * .from(users)\n\t * .union(\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * // or\n\t * import { union } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await union(\n\t * db.select({ name: users.name }).from(users),\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * ```\n\t */\n\tunion = this.createSetOperator('union', false);\n\n\t/**\n\t * Adds `union all` set operator to the query.\n\t *\n\t * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all transaction ids from both online and in-store sales\n\t * await db.select({ transaction: onlineSales.transactionId })\n\t * .from(onlineSales)\n\t * .unionAll(\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * // or\n\t * import { unionAll } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await unionAll(\n\t * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * ```\n\t */\n\tunionAll = this.createSetOperator('union', true);\n\n\t/**\n\t * Adds `intersect` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select course names that are offered in both departments A and B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .intersect(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { intersect } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await intersect(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tintersect = this.createSetOperator('intersect', false);\n\n\t/**\n\t * Adds `except` set operator to the query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .except(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { except } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await except(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\texcept = this.createSetOperator('except', false);\n\n\t/**\n\t * Adds `minus` set operator to the query.\n\t *\n\t * This is an alias of `except` supported by SingleStore.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .minus(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { minus } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await minus(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tminus = this.createSetOperator('except', false);\n\n\t/** @internal */\n\taddSetOperators(setOperators: SingleStoreSelectConfig['setOperators']): SingleStoreSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tSingleStoreSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\tthis.config.setOperators.push(...setOperators);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#filtering}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be selected.\n\t *\n\t * ```ts\n\t * // Select all cars with green color\n\t * await db.select().from(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * await db.select().from(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Select all BMW cars with a green color\n\t * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Select all cars with the green or blue color\n\t * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(\n\t\twhere: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): SingleStoreSelectWithout<this, TDynamic, 'where'> {\n\t\tif (typeof where === 'function') {\n\t\t\twhere = where(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `having` clause to the query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @param having the `having` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all brands with more than one car\n\t * await db.select({\n\t * \tbrand: cars.brand,\n\t * \tcount: sql<number>`cast(count(${cars.id}) as int)`,\n\t * })\n\t * .from(cars)\n\t * .groupBy(cars.brand)\n\t * .having(({ count }) => gt(count, 1));\n\t * ```\n\t */\n\thaving(\n\t\thaving: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): SingleStoreSelectWithout<this, TDynamic, 'having'> {\n\t\tif (typeof having === 'function') {\n\t\t\thaving = having(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.having = having;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `group by` clause to the query.\n\t *\n\t * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Group and count people by their last names\n\t * await db.select({\n\t * lastName: people.lastName,\n\t * count: sql<number>`cast(count(*) as int)`\n\t * })\n\t * .from(people)\n\t * .groupBy(people.lastName);\n\t * ```\n\t */\n\tgroupBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>,\n\t): SingleStoreSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(...columns: (SingleStoreColumn | SQL | SQL.Aliased)[]): SingleStoreSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>]\n\t\t\t| (SingleStoreColumn | SQL | SQL.Aliased)[]\n\t): SingleStoreSelectWithout<this, TDynamic, 'groupBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst groupBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t\tthis.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];\n\t\t} else {\n\t\t\tthis.config.groupBy = columns as (SingleStoreColumn | SQL | SQL.Aliased)[];\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `order by` clause to the query.\n\t *\n\t * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#order-by}\n\t *\n\t * @example\n\t *\n\t * ```\n\t * // Select cars ordered by year\n\t * await db.select().from(cars).orderBy(cars.year);\n\t * ```\n\t *\n\t * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.\n\t *\n\t * ```ts\n\t * // Select cars ordered by year in descending order\n\t * await db.select().from(cars).orderBy(desc(cars.year));\n\t *\n\t * // Select cars ordered by year and price\n\t * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));\n\t * ```\n\t */\n\torderBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>,\n\t): SingleStoreSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SingleStoreColumn | SQL | SQL.Aliased)[]): SingleStoreSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>]\n\t\t\t| (SingleStoreColumn | SQL | SQL.Aliased)[]\n\t): SingleStoreSelectWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SingleStoreColumn | SQL | SQL.Aliased)[];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `limit` clause to the query.\n\t *\n\t * Calling this method will set the maximum number of rows that will be returned by this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param limit the `limit` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the first 10 people from this query.\n\t * await db.select().from(people).limit(10);\n\t * ```\n\t */\n\tlimit(limit: number): SingleStoreSelectWithout<this, TDynamic, 'limit'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.limit = limit;\n\t\t} else {\n\t\t\tthis.config.limit = limit;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `offset` clause to the query.\n\t *\n\t * Calling this method will skip a number of rows when returning results from this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param offset the `offset` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the 10th-20th people from this query.\n\t * await db.select().from(people).offset(10).limit(10);\n\t * ```\n\t */\n\toffset(offset: number): SingleStoreSelectWithout<this, TDynamic, 'offset'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.offset = offset;\n\t\t} else {\n\t\t\tthis.config.offset = offset;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `for` clause to the query.\n\t *\n\t * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.\n\t *\n\t * @param strength the lock strength.\n\t * @param config the lock configuration.\n\t */\n\tfor(strength: LockStrength, config: LockConfig = {}): SingleStoreSelectWithout<this, TDynamic, 'for'> {\n\t\tthis.config.lockingClause = { strength, config };\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildSelectQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tas<TAlias extends string>(\n\t\talias: TAlias,\n\t): SubqueryWithSelection<this['_']['selectedFields'], TAlias> {\n\t\treturn new Proxy(\n\t\t\tnew Subquery(this.getSQL(), this.config.fields, alias),\n\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as SubqueryWithSelection<this['_']['selectedFields'], TAlias>;\n\t}\n\n\t/** @internal */\n\toverride getSelectedFields(): this['_']['selectedFields'] {\n\t\treturn new Proxy(\n\t\t\tthis.config.fields,\n\t\t\tnew SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as this['_']['selectedFields'];\n\t}\n\n\t$dynamic(): SingleStoreSelectDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n\nexport interface SingleStoreSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends\n\tSingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tQueryPromise<TResult>\n{}\n\nexport class SingleStoreSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends SingleStoreSelectQueryBuilderBase<\n\tSingleStoreSelectHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\tTDynamic,\n\tTExcludedMethods,\n\tTResult,\n\tTSelectedFields\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreSelect';\n\n\tprepare(): SingleStoreSelectPrepare<this> {\n\t\tif (!this.session) {\n\t\t\tthrow new Error('Cannot execute a query on a query builder. Please use a database instance instead.');\n\t\t}\n\t\tconst fieldsList = orderSelectedFields<SingleStoreColumn>(this.config.fields);\n\t\tconst query = this.session.prepareQuery<\n\t\t\tSingleStorePreparedQueryConfig & { execute: SelectResult<TSelection, TSelectMode, TNullabilityMap>[] },\n\t\t\tTPreparedQueryHKT\n\t\t>(this.dialect.sqlToQuery(this.getSQL()), fieldsList);\n\t\tquery.joinsNotNullableMap = this.joinsNotNullableMap;\n\t\treturn query as SingleStoreSelectPrepare<this>;\n\t}\n\n\texecute = ((placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t}) as ReturnType<this['prepare']>['execute'];\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n}\n\napplyMixins(SingleStoreSelectBase, [QueryPromise]);\n\nfunction createSetOperator(type: SetOperator, isAll: boolean): SingleStoreCreateSetOperatorFn {\n\treturn (leftSelect, rightSelect, ...restSelects) => {\n\t\tconst setOperators = [rightSelect, ...restSelects].map((select) => ({\n\t\t\ttype,\n\t\t\tisAll,\n\t\t\trightSelect: select as AnySingleStoreSelect,\n\t\t}));\n\n\t\tfor (const setOperator of setOperators) {\n\t\t\tif (!haveSameKeys((leftSelect as any).getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (leftSelect as AnySingleStoreSelect).addSetOperators(setOperators) as any;\n\t};\n}\n\nconst getSingleStoreSetOperators = () => ({\n\tunion,\n\tunionAll,\n\tintersect,\n\texcept,\n\tminus,\n});\n\n/**\n * Adds `union` set operator to the query.\n *\n * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n *\n * @example\n *\n * ```ts\n * // Select all unique names from customers and users tables\n * import { union } from 'drizzle-orm/singlestore-core'\n *\n * await union(\n * db.select({ name: users.name }).from(users),\n * db.select({ name: customers.name }).from(customers)\n * );\n * // or\n * await db.select({ name: users.name })\n * .from(users)\n * .union(\n * db.select({ name: customers.name }).from(customers)\n * );\n * ```\n */\nexport const union = createSetOperator('union', false);\n\n/**\n * Adds `union all` set operator to the query.\n *\n * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n *\n * @example\n *\n * ```ts\n * // Select all transaction ids from both online and in-store sales\n * import { unionAll } from 'drizzle-orm/singlestore-core'\n *\n * await unionAll(\n * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * // or\n * await db.select({ transaction: onlineSales.transactionId })\n * .from(onlineSales)\n * .unionAll(\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * ```\n */\nexport const unionAll = createSetOperator('union', true);\n\n/**\n * Adds `intersect` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n *\n * @example\n *\n * ```ts\n * // Select course names that are offered in both departments A and B\n * import { intersect } from 'drizzle-orm/singlestore-core'\n *\n * await intersect(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .intersect(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const intersect = createSetOperator('intersect', false);\n\n/**\n * Adds `except` set operator to the query.\n *\n * 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.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { except } from 'drizzle-orm/singlestore-core'\n *\n * await except(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .except(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const except = createSetOperator('except', false);\n\n/**\n * Adds `minus` set operator to the query.\n *\n * This is an alias of `except` supported by SingleStore.\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { minus } from 'drizzle-orm/singlestore-core'\n *\n * await minus(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .minus(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const minus = createSetOperator('except', true);\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAC/B,SAAS,yBAAyB;AAWlC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAWtC,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAqBA,MAAM,yBAIX;AAAA,EACD,QAAiB,UAAU,IAAY;AAAA,EAE/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAuB,CAAC;AAAA,EACxB;AAAA,EAER,YACC,QAOC;AACD,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,QAAI,OAAO,UAAU;AACpB,WAAK,WAAW,OAAO;AAAA,IACxB;AACA,SAAK,WAAW,OAAO;AAAA,EACxB;AAAA,EAEA,KACC,QAOC;AACD,UAAM,kBAAkB,CAAC,CAAC,KAAK;AAE/B,QAAI;AACJ,QAAI,KAAK,QAAQ;AAChB,eAAS,KAAK;AAAA,IACf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,iBAAiB,MAA+C;AACvE,UAAM,OAAO;AACb,WAAO,iBAAgB,mBAAmB;AACzC,aAAO,KAAK,QAAQ,EAAE,SAAS,iBAAiB;AAAA,IACjD;AAAA,EACD;AAAA,EAEA,WAAW,KAAK,eAAe;AAChC;AAEA,YAAY,uBAAuB,CAAC,YAAY,CAAC;AAEjD,SAAS,kBAAkB,MAAmB,OAAgD;AAC7F,SAAO,CAAC,YAAY,gBAAgB,gBAAgB;AACnD,UAAM,eAAe,CAAC,aAAa,GAAG,WAAW,EAAE,IAAI,CAAC,YAAY;AAAA,MACnE;AAAA,MACA;AAAA,MACA,aAAa;AAAA,IACd,EAAE;AAEF,eAAW,eAAe,cAAc;AACvC,UAAI,CAAC,aAAc,WAAmB,kBAAkB,GAAG,YAAY,YAAY,kBAAkB,CAAC,GAAG;AACxG,cAAM,IAAI;AAAA,UACT;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,WAAQ,WAAoC,gBAAgB,YAAY;AAAA,EACzE;AACD;AAEA,MAAM,6BAA6B,OAAO;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AA2BO,MAAM,QAAQ,kBAAkB,SAAS,KAAK;AA2B9C,MAAM,WAAW,kBAAkB,SAAS,IAAI;AA2BhD,MAAM,YAAY,kBAAkB,aAAa,KAAK;AA2BtD,MAAM,SAAS,kBAAkB,UAAU,KAAK;AAyBhD,MAAM,QAAQ,kBAAkB,UAAU,IAAI;","names":[]}
1
+ {"version":3,"sources":["../../../src/singlestore-core/query-builders/select.ts"],"sourcesContent":["import { entityKind, is } from '~/entity.ts';\nimport { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tGetSelectTableSelection,\n\tJoinNullability,\n\tJoinType,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport { QueryPromise } from '~/query-promise.ts';\nimport { SelectionProxyHandler } from '~/selection-proxy.ts';\nimport type { SingleStoreColumn } from '~/singlestore-core/columns/index.ts';\nimport type { SingleStoreDialect } from '~/singlestore-core/dialect.ts';\nimport type {\n\tPreparedQueryHKTBase,\n\tSingleStorePreparedQueryConfig,\n\tSingleStoreSession,\n} from '~/singlestore-core/session.ts';\nimport type { SubqueryWithSelection } from '~/singlestore-core/subquery.ts';\nimport type { SingleStoreTable } from '~/singlestore-core/table.ts';\nimport type { ColumnsSelection, Query } from '~/sql/sql.ts';\nimport { SQL } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { Table } from '~/table.ts';\nimport {\n\tapplyMixins,\n\tgetTableColumns,\n\tgetTableLikeName,\n\thaveSameKeys,\n\torderSelectedFields,\n\ttype ValueOrArray,\n} from '~/utils.ts';\nimport type {\n\tAnySingleStoreSelect,\n\tCreateSingleStoreSelectFromBuilderMode,\n\tGetSingleStoreSetOperators,\n\tLockConfig,\n\tLockStrength,\n\tSelectedFields,\n\tSetOperatorRightSelect,\n\tSingleStoreCreateSetOperatorFn,\n\tSingleStoreJoinFn,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectDynamic,\n\tSingleStoreSelectHKT,\n\tSingleStoreSelectHKTBase,\n\tSingleStoreSelectPrepare,\n\tSingleStoreSelectWithout,\n\tSingleStoreSetOperatorExcludedMethods,\n\tSingleStoreSetOperatorWithResult,\n} from './select.types.ts';\n\nexport class SingleStoreSelectBuilder<\n\tTSelection extends SelectedFields | undefined,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTBuilderMode extends 'db' | 'qb' = 'db',\n> {\n\tstatic readonly [entityKind]: string = 'SingleStoreSelectBuilder';\n\n\tprivate fields: TSelection;\n\tprivate session: SingleStoreSession | undefined;\n\tprivate dialect: SingleStoreDialect;\n\tprivate withList: Subquery[] = [];\n\tprivate distinct: boolean | undefined;\n\n\tconstructor(\n\t\tconfig: {\n\t\t\tfields: TSelection;\n\t\t\tsession: SingleStoreSession | undefined;\n\t\t\tdialect: SingleStoreDialect;\n\t\t\twithList?: Subquery[];\n\t\t\tdistinct?: boolean;\n\t\t},\n\t) {\n\t\tthis.fields = config.fields;\n\t\tthis.session = config.session;\n\t\tthis.dialect = config.dialect;\n\t\tif (config.withList) {\n\t\t\tthis.withList = config.withList;\n\t\t}\n\t\tthis.distinct = config.distinct;\n\t}\n\n\tfrom<TFrom extends SingleStoreTable | Subquery | SQL>( // | SingleStoreViewBase\n\t\tsource: TFrom,\n\t): CreateSingleStoreSelectFromBuilderMode<\n\t\tTBuilderMode,\n\t\tGetSelectTableName<TFrom>,\n\t\tTSelection extends undefined ? GetSelectTableSelection<TFrom> : TSelection,\n\t\tTSelection extends undefined ? 'single' : 'partial',\n\t\tTPreparedQueryHKT\n\t> {\n\t\tconst isPartialSelect = !!this.fields;\n\n\t\tlet fields: SelectedFields;\n\t\tif (this.fields) {\n\t\t\tfields = this.fields;\n\t\t} else if (is(source, Subquery)) {\n\t\t\t// This is required to use the proxy handler to get the correct field values from the subquery\n\t\t\tfields = Object.fromEntries(\n\t\t\t\tObject.keys(source._.selectedFields).map((\n\t\t\t\t\tkey,\n\t\t\t\t) => [key, source[key as unknown as keyof typeof source] as unknown as SelectedFields[string]]),\n\t\t\t);\n\t\t\t/* } else if (is(source, SingleStoreViewBase)) {\n\t\t\tfields = source[ViewBaseConfig].selectedFields as SelectedFields; */\n\t\t} else if (is(source, SQL)) {\n\t\t\tfields = {};\n\t\t} else {\n\t\t\tfields = getTableColumns<SingleStoreTable>(source);\n\t\t}\n\n\t\treturn new SingleStoreSelectBase(\n\t\t\t{\n\t\t\t\ttable: source,\n\t\t\t\tfields,\n\t\t\t\tisPartialSelect,\n\t\t\t\tsession: this.session,\n\t\t\t\tdialect: this.dialect,\n\t\t\t\twithList: this.withList,\n\t\t\t\tdistinct: this.distinct,\n\t\t\t},\n\t\t) as any;\n\t}\n}\n\nexport abstract class SingleStoreSelectQueryBuilderBase<\n\tTHKT extends SingleStoreSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends TypedQueryBuilder<TSelectedFields, TResult> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreSelectQueryBuilder';\n\n\toverride readonly _: {\n\t\treadonly hkt: THKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n\n\tprotected config: SingleStoreSelectConfig;\n\tprotected joinsNotNullableMap: Record<string, boolean>;\n\tprivate tableName: string | undefined;\n\tprivate isPartialSelect: boolean;\n\t/** @internal */\n\treadonly session: SingleStoreSession | undefined;\n\tprotected dialect: SingleStoreDialect;\n\n\tconstructor(\n\t\t{ table, fields, isPartialSelect, session, dialect, withList, distinct }: {\n\t\t\ttable: SingleStoreSelectConfig['table'];\n\t\t\tfields: SingleStoreSelectConfig['fields'];\n\t\t\tisPartialSelect: boolean;\n\t\t\tsession: SingleStoreSession | undefined;\n\t\t\tdialect: SingleStoreDialect;\n\t\t\twithList: Subquery[];\n\t\t\tdistinct: boolean | undefined;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.config = {\n\t\t\twithList,\n\t\t\ttable,\n\t\t\tfields: { ...fields },\n\t\t\tdistinct,\n\t\t\tsetOperators: [],\n\t\t};\n\t\tthis.isPartialSelect = isPartialSelect;\n\t\tthis.session = session;\n\t\tthis.dialect = dialect;\n\t\tthis._ = {\n\t\t\tselectedFields: fields as TSelectedFields,\n\t\t} as this['_'];\n\t\tthis.tableName = getTableLikeName(table);\n\t\tthis.joinsNotNullableMap = typeof this.tableName === 'string' ? { [this.tableName]: true } : {};\n\t}\n\n\tprivate createJoin<\n\t\tTJoinType extends JoinType,\n\t\tTIsLateral extends (TJoinType extends 'full' | 'right' ? false : boolean),\n\t>(\n\t\tjoinType: TJoinType,\n\t\tlateral: TIsLateral,\n\t): SingleStoreJoinFn<this, TDynamic, TJoinType, TIsLateral> {\n\t\treturn (\n\t\t\ttable: SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\t\t\ton?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,\n\t\t) => {\n\t\t\tconst baseTableName = this.tableName;\n\t\t\tconst tableName = getTableLikeName(table);\n\n\t\t\tif (typeof tableName === 'string' && this.config.joins?.some((join) => join.alias === tableName)) {\n\t\t\t\tthrow new Error(`Alias \"${tableName}\" is already used in this query`);\n\t\t\t}\n\n\t\t\tif (!this.isPartialSelect) {\n\t\t\t\t// If this is the first join and this is not a partial select and we're not selecting from raw SQL, \"move\" the fields from the main table to the nested object\n\t\t\t\tif (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === 'string') {\n\t\t\t\t\tthis.config.fields = {\n\t\t\t\t\t\t[baseTableName]: this.config.fields,\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tif (typeof tableName === 'string' && !is(table, SQL)) {\n\t\t\t\t\tconst selection = is(table, Subquery)\n\t\t\t\t\t\t? table._.selectedFields\n\t\t\t\t\t\t/* : is(table, View)\n\t\t\t\t\t\t? table[ViewBaseConfig].selectedFields */\n\t\t\t\t\t\t: table[Table.Symbol.Columns];\n\t\t\t\t\tthis.config.fields[tableName] = selection;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (typeof on === 'function') {\n\t\t\t\ton = on(\n\t\t\t\t\tnew Proxy(\n\t\t\t\t\t\tthis.config.fields,\n\t\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t\t) as TSelection,\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tif (!this.config.joins) {\n\t\t\t\tthis.config.joins = [];\n\t\t\t}\n\n\t\t\tthis.config.joins.push({ on, table, joinType, alias: tableName, lateral });\n\n\t\t\tif (typeof tableName === 'string') {\n\t\t\t\tswitch (joinType) {\n\t\t\t\t\tcase 'left': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'right': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'cross':\n\t\t\t\t\tcase 'inner': {\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = true;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\tcase 'full': {\n\t\t\t\t\t\tthis.joinsNotNullableMap = Object.fromEntries(\n\t\t\t\t\t\t\tObject.entries(this.joinsNotNullableMap).map(([key]) => [key, false]),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tthis.joinsNotNullableMap[tableName] = false;\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Executes a `left join` operation by adding another table to the current query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet | null; }[] = await db.select()\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .leftJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tleftJoin = this.createJoin('left', false);\n\n\t/**\n\t * Executes a `left join lateral` operation by adding subquery to the current query.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#left-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tleftJoinLateral = this.createJoin('left', true);\n\n\t/**\n\t * Executes a `right join` operation by adding another table to the current query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#right-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .rightJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\trightJoin = this.createJoin('right', false);\n\n\t/**\n\t * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .innerJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tinnerJoin = this.createJoin('inner', false);\n\n\t/**\n\t * Executes an `inner join lateral` operation, creating a new table by combining rows from two queries that have matching values.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join-lateral}\n\t *\n\t * @param table the subquery to join.\n\t * @param on the `on` clause.\n\t */\n\tinnerJoinLateral = this.createJoin('inner', true);\n\n\t/**\n\t * Executes a `full join` operation by combining rows from two tables into a new table.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#full-join}\n\t *\n\t * @param table the table to join.\n\t * @param on the `on` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users and their pets\n\t * const usersWithPets: { user: User | null; pets: Pet | null; }[] = await db.select()\n\t * .from(users)\n\t * .fullJoin(pets, eq(users.id, pets.ownerId))\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number | null; petId: number | null; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .fullJoin(pets, eq(users.id, pets.ownerId))\n\t * ```\n\t */\n\tfullJoin = this.createJoin('full', false);\n\n\t/**\n\t * Executes a `cross join` operation by combining rows from two tables into a new table.\n\t *\n\t * Calling this method retrieves all rows from both main and joined tables, merging all rows from each table.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join}\n\t *\n\t * @param table the table to join.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all users, each user with every pet\n\t * const usersWithPets: { user: User; pets: Pet; }[] = await db.select()\n\t * .from(users)\n\t * .crossJoin(pets)\n\t *\n\t * // Select userId and petId\n\t * const usersIdsAndPetIds: { userId: number; petId: number; }[] = await db.select({\n\t * userId: users.id,\n\t * petId: pets.id,\n\t * })\n\t * .from(users)\n\t * .crossJoin(pets)\n\t * ```\n\t */\n\tcrossJoin = this.createJoin('cross', false);\n\n\t/**\n\t * Executes a `cross join lateral` operation by combining rows from two queries into a new table.\n\t *\n\t * A `lateral` join allows the right-hand expression to refer to columns from the left-hand side.\n\t *\n\t * Calling this method retrieves all rows from both main and joined queries, merging all rows from each query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/joins#cross-join-lateral}\n\t *\n\t * @param table the query to join.\n\t */\n\tcrossJoinLateral = this.createJoin('cross', true);\n\n\tprivate createSetOperator(\n\t\ttype: SetOperator,\n\t\tisAll: boolean,\n\t): <TValue extends SingleStoreSetOperatorWithResult<TResult>>(\n\t\trightSelection:\n\t\t\t| ((setOperators: GetSingleStoreSetOperators) => SetOperatorRightSelect<TValue, TResult>)\n\t\t\t| SetOperatorRightSelect<TValue, TResult>,\n\t) => SingleStoreSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tSingleStoreSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\treturn (rightSelection) => {\n\t\t\tconst rightSelect = (typeof rightSelection === 'function'\n\t\t\t\t? rightSelection(getSingleStoreSetOperators())\n\t\t\t\t: rightSelection) as TypedQueryBuilder<\n\t\t\t\t\tany,\n\t\t\t\t\tTResult\n\t\t\t\t>;\n\n\t\t\tif (!haveSameKeys(this.getSelectedFields(), rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tthis.config.setOperators.push({ type, isAll, rightSelect });\n\t\t\treturn this as any;\n\t\t};\n\t}\n\n\t/**\n\t * Adds `union` set operator to the query.\n\t *\n\t * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all unique names from customers and users tables\n\t * await db.select({ name: users.name })\n\t * .from(users)\n\t * .union(\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * // or\n\t * import { union } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await union(\n\t * db.select({ name: users.name }).from(users),\n\t * db.select({ name: customers.name }).from(customers)\n\t * );\n\t * ```\n\t */\n\tunion = this.createSetOperator('union', false);\n\n\t/**\n\t * Adds `union all` set operator to the query.\n\t *\n\t * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all transaction ids from both online and in-store sales\n\t * await db.select({ transaction: onlineSales.transactionId })\n\t * .from(onlineSales)\n\t * .unionAll(\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * // or\n\t * import { unionAll } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await unionAll(\n\t * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n\t * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n\t * );\n\t * ```\n\t */\n\tunionAll = this.createSetOperator('union', true);\n\n\t/**\n\t * Adds `intersect` set operator to the query.\n\t *\n\t * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select course names that are offered in both departments A and B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .intersect(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { intersect } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await intersect(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tintersect = this.createSetOperator('intersect', false);\n\n\t/**\n\t * Adds `except` set operator to the query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .except(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { except } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await except(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\texcept = this.createSetOperator('except', false);\n\n\t/**\n\t * Adds `minus` set operator to the query.\n\t *\n\t * This is an alias of `except` supported by SingleStore.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all courses offered in department A but not in department B\n\t * await db.select({ courseName: depA.courseName })\n\t * .from(depA)\n\t * .minus(\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * // or\n\t * import { minus } from 'drizzle-orm/singlestore-core'\n\t *\n\t * await minus(\n\t * db.select({ courseName: depA.courseName }).from(depA),\n\t * db.select({ courseName: depB.courseName }).from(depB)\n\t * );\n\t * ```\n\t */\n\tminus = this.createSetOperator('except', false);\n\n\t/** @internal */\n\taddSetOperators(setOperators: SingleStoreSelectConfig['setOperators']): SingleStoreSelectWithout<\n\t\tthis,\n\t\tTDynamic,\n\t\tSingleStoreSetOperatorExcludedMethods,\n\t\ttrue\n\t> {\n\t\tthis.config.setOperators.push(...setOperators);\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `where` clause to the query.\n\t *\n\t * Calling this method will select only those rows that fulfill a specified condition.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#filtering}\n\t *\n\t * @param where the `where` clause.\n\t *\n\t * @example\n\t * You can use conditional operators and `sql function` to filter the rows to be selected.\n\t *\n\t * ```ts\n\t * // Select all cars with green color\n\t * await db.select().from(cars).where(eq(cars.color, 'green'));\n\t * // or\n\t * await db.select().from(cars).where(sql`${cars.color} = 'green'`)\n\t * ```\n\t *\n\t * You can logically combine conditional operators with `and()` and `or()` operators:\n\t *\n\t * ```ts\n\t * // Select all BMW cars with a green color\n\t * await db.select().from(cars).where(and(eq(cars.color, 'green'), eq(cars.brand, 'BMW')));\n\t *\n\t * // Select all cars with the green or blue color\n\t * await db.select().from(cars).where(or(eq(cars.color, 'green'), eq(cars.color, 'blue')));\n\t * ```\n\t */\n\twhere(\n\t\twhere: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): SingleStoreSelectWithout<this, TDynamic, 'where'> {\n\t\tif (typeof where === 'function') {\n\t\t\twhere = where(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.where = where;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `having` clause to the query.\n\t *\n\t * 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.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @param having the `having` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Select all brands with more than one car\n\t * await db.select({\n\t * \tbrand: cars.brand,\n\t * \tcount: sql<number>`cast(count(${cars.id}) as int)`,\n\t * })\n\t * .from(cars)\n\t * .groupBy(cars.brand)\n\t * .having(({ count }) => gt(count, 1));\n\t * ```\n\t */\n\thaving(\n\t\thaving: ((aliases: this['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t): SingleStoreSelectWithout<this, TDynamic, 'having'> {\n\t\tif (typeof having === 'function') {\n\t\t\thaving = having(\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'sql', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t}\n\t\tthis.config.having = having;\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `group by` clause to the query.\n\t *\n\t * Calling this method will group rows that have the same values into summary rows, often used for aggregation purposes.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#aggregations}\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Group and count people by their last names\n\t * await db.select({\n\t * lastName: people.lastName,\n\t * count: sql<number>`cast(count(*) as int)`\n\t * })\n\t * .from(people)\n\t * .groupBy(people.lastName);\n\t * ```\n\t */\n\tgroupBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>,\n\t): SingleStoreSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(...columns: (SingleStoreColumn | SQL | SQL.Aliased)[]): SingleStoreSelectWithout<this, TDynamic, 'groupBy'>;\n\tgroupBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>]\n\t\t\t| (SingleStoreColumn | SQL | SQL.Aliased)[]\n\t): SingleStoreSelectWithout<this, TDynamic, 'groupBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst groupBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\t\t\tthis.config.groupBy = Array.isArray(groupBy) ? groupBy : [groupBy];\n\t\t} else {\n\t\t\tthis.config.groupBy = columns as (SingleStoreColumn | SQL | SQL.Aliased)[];\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `order by` clause to the query.\n\t *\n\t * Calling this method will sort the result-set in ascending or descending order. By default, the sort order is ascending.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#order-by}\n\t *\n\t * @example\n\t *\n\t * ```\n\t * // Select cars ordered by year\n\t * await db.select().from(cars).orderBy(cars.year);\n\t * ```\n\t *\n\t * You can specify whether results are in ascending or descending order with the `asc()` and `desc()` operators.\n\t *\n\t * ```ts\n\t * // Select cars ordered by year in descending order\n\t * await db.select().from(cars).orderBy(desc(cars.year));\n\t *\n\t * // Select cars ordered by year and price\n\t * await db.select().from(cars).orderBy(asc(cars.year), desc(cars.price));\n\t * ```\n\t */\n\torderBy(\n\t\tbuilder: (aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>,\n\t): SingleStoreSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(...columns: (SingleStoreColumn | SQL | SQL.Aliased)[]): SingleStoreSelectWithout<this, TDynamic, 'orderBy'>;\n\torderBy(\n\t\t...columns:\n\t\t\t| [(aliases: this['_']['selection']) => ValueOrArray<SingleStoreColumn | SQL | SQL.Aliased>]\n\t\t\t| (SingleStoreColumn | SQL | SQL.Aliased)[]\n\t): SingleStoreSelectWithout<this, TDynamic, 'orderBy'> {\n\t\tif (typeof columns[0] === 'function') {\n\t\t\tconst orderBy = columns[0](\n\t\t\t\tnew Proxy(\n\t\t\t\t\tthis.config.fields,\n\t\t\t\t\tnew SelectionProxyHandler({ sqlAliasedBehavior: 'alias', sqlBehavior: 'sql' }),\n\t\t\t\t) as TSelection,\n\t\t\t);\n\n\t\t\tconst orderByArray = Array.isArray(orderBy) ? orderBy : [orderBy];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t} else {\n\t\t\tconst orderByArray = columns as (SingleStoreColumn | SQL | SQL.Aliased)[];\n\n\t\t\tif (this.config.setOperators.length > 0) {\n\t\t\t\tthis.config.setOperators.at(-1)!.orderBy = orderByArray;\n\t\t\t} else {\n\t\t\t\tthis.config.orderBy = orderByArray;\n\t\t\t}\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `limit` clause to the query.\n\t *\n\t * Calling this method will set the maximum number of rows that will be returned by this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param limit the `limit` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the first 10 people from this query.\n\t * await db.select().from(people).limit(10);\n\t * ```\n\t */\n\tlimit(limit: number): SingleStoreSelectWithout<this, TDynamic, 'limit'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.limit = limit;\n\t\t} else {\n\t\t\tthis.config.limit = limit;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds an `offset` clause to the query.\n\t *\n\t * Calling this method will skip a number of rows when returning results from this query.\n\t *\n\t * See docs: {@link https://orm.drizzle.team/docs/select#limit--offset}\n\t *\n\t * @param offset the `offset` clause.\n\t *\n\t * @example\n\t *\n\t * ```ts\n\t * // Get the 10th-20th people from this query.\n\t * await db.select().from(people).offset(10).limit(10);\n\t * ```\n\t */\n\toffset(offset: number): SingleStoreSelectWithout<this, TDynamic, 'offset'> {\n\t\tif (this.config.setOperators.length > 0) {\n\t\t\tthis.config.setOperators.at(-1)!.offset = offset;\n\t\t} else {\n\t\t\tthis.config.offset = offset;\n\t\t}\n\t\treturn this as any;\n\t}\n\n\t/**\n\t * Adds a `for` clause to the query.\n\t *\n\t * Calling this method will specify a lock strength for this query that controls how strictly it acquires exclusive access to the rows being queried.\n\t *\n\t * @param strength the lock strength.\n\t * @param config the lock configuration.\n\t */\n\tfor(strength: LockStrength, config: LockConfig = {}): SingleStoreSelectWithout<this, TDynamic, 'for'> {\n\t\tthis.config.lockingClause = { strength, config };\n\t\treturn this as any;\n\t}\n\n\t/** @internal */\n\tgetSQL(): SQL {\n\t\treturn this.dialect.buildSelectQuery(this.config);\n\t}\n\n\ttoSQL(): Query {\n\t\tconst { typings: _typings, ...rest } = this.dialect.sqlToQuery(this.getSQL());\n\t\treturn rest;\n\t}\n\n\tas<TAlias extends string>(\n\t\talias: TAlias,\n\t): SubqueryWithSelection<this['_']['selectedFields'], TAlias> {\n\t\treturn new Proxy(\n\t\t\tnew Subquery(this.getSQL(), this.config.fields, alias),\n\t\t\tnew SelectionProxyHandler({ alias, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as SubqueryWithSelection<this['_']['selectedFields'], TAlias>;\n\t}\n\n\t/** @internal */\n\toverride getSelectedFields(): this['_']['selectedFields'] {\n\t\treturn new Proxy(\n\t\t\tthis.config.fields,\n\t\t\tnew SelectionProxyHandler({ alias: this.tableName, sqlAliasedBehavior: 'alias', sqlBehavior: 'error' }),\n\t\t) as this['_']['selectedFields'];\n\t}\n\n\t$dynamic(): SingleStoreSelectDynamic<this> {\n\t\treturn this as any;\n\t}\n}\n\nexport interface SingleStoreSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends\n\tSingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tQueryPromise<TResult>\n{}\n\nexport class SingleStoreSelectBase<\n\tTTableName extends string | undefined,\n\tTSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> extends SingleStoreSelectQueryBuilderBase<\n\tSingleStoreSelectHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\tTDynamic,\n\tTExcludedMethods,\n\tTResult,\n\tTSelectedFields\n> {\n\tstatic override readonly [entityKind]: string = 'SingleStoreSelect';\n\n\tprepare(): SingleStoreSelectPrepare<this> {\n\t\tif (!this.session) {\n\t\t\tthrow new Error('Cannot execute a query on a query builder. Please use a database instance instead.');\n\t\t}\n\t\tconst fieldsList = orderSelectedFields<SingleStoreColumn>(this.config.fields);\n\t\tconst query = this.session.prepareQuery<\n\t\t\tSingleStorePreparedQueryConfig & { execute: SelectResult<TSelection, TSelectMode, TNullabilityMap>[] },\n\t\t\tTPreparedQueryHKT\n\t\t>(this.dialect.sqlToQuery(this.getSQL()), fieldsList);\n\t\tquery.joinsNotNullableMap = this.joinsNotNullableMap;\n\t\treturn query as SingleStoreSelectPrepare<this>;\n\t}\n\n\texecute = ((placeholderValues) => {\n\t\treturn this.prepare().execute(placeholderValues);\n\t}) as ReturnType<this['prepare']>['execute'];\n\n\tprivate createIterator = (): ReturnType<this['prepare']>['iterator'] => {\n\t\tconst self = this;\n\t\treturn async function*(placeholderValues) {\n\t\t\tyield* self.prepare().iterator(placeholderValues);\n\t\t};\n\t};\n\n\titerator = this.createIterator();\n}\n\napplyMixins(SingleStoreSelectBase, [QueryPromise]);\n\nfunction createSetOperator(type: SetOperator, isAll: boolean): SingleStoreCreateSetOperatorFn {\n\treturn (leftSelect, rightSelect, ...restSelects) => {\n\t\tconst setOperators = [rightSelect, ...restSelects].map((select) => ({\n\t\t\ttype,\n\t\t\tisAll,\n\t\t\trightSelect: select as AnySingleStoreSelect,\n\t\t}));\n\n\t\tfor (const setOperator of setOperators) {\n\t\t\tif (!haveSameKeys((leftSelect as any).getSelectedFields(), setOperator.rightSelect.getSelectedFields())) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t'Set operator error (union / intersect / except): selected fields are not the same or are in a different order',\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\treturn (leftSelect as AnySingleStoreSelect).addSetOperators(setOperators) as any;\n\t};\n}\n\nconst getSingleStoreSetOperators = () => ({\n\tunion,\n\tunionAll,\n\tintersect,\n\texcept,\n\tminus,\n});\n\n/**\n * Adds `union` set operator to the query.\n *\n * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union}\n *\n * @example\n *\n * ```ts\n * // Select all unique names from customers and users tables\n * import { union } from 'drizzle-orm/singlestore-core'\n *\n * await union(\n * db.select({ name: users.name }).from(users),\n * db.select({ name: customers.name }).from(customers)\n * );\n * // or\n * await db.select({ name: users.name })\n * .from(users)\n * .union(\n * db.select({ name: customers.name }).from(customers)\n * );\n * ```\n */\nexport const union = createSetOperator('union', false);\n\n/**\n * Adds `union all` set operator to the query.\n *\n * Calling this method will combine the result-set of the `select` statements and keep all duplicate rows that appear across them.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#union-all}\n *\n * @example\n *\n * ```ts\n * // Select all transaction ids from both online and in-store sales\n * import { unionAll } from 'drizzle-orm/singlestore-core'\n *\n * await unionAll(\n * db.select({ transaction: onlineSales.transactionId }).from(onlineSales),\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * // or\n * await db.select({ transaction: onlineSales.transactionId })\n * .from(onlineSales)\n * .unionAll(\n * db.select({ transaction: inStoreSales.transactionId }).from(inStoreSales)\n * );\n * ```\n */\nexport const unionAll = createSetOperator('union', true);\n\n/**\n * Adds `intersect` set operator to the query.\n *\n * Calling this method will retain only the rows that are present in both result sets and eliminate duplicates.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#intersect}\n *\n * @example\n *\n * ```ts\n * // Select course names that are offered in both departments A and B\n * import { intersect } from 'drizzle-orm/singlestore-core'\n *\n * await intersect(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .intersect(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const intersect = createSetOperator('intersect', false);\n\n/**\n * Adds `except` set operator to the query.\n *\n * 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.\n *\n * See docs: {@link https://orm.drizzle.team/docs/set-operations#except}\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { except } from 'drizzle-orm/singlestore-core'\n *\n * await except(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .except(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const except = createSetOperator('except', false);\n\n/**\n * Adds `minus` set operator to the query.\n *\n * This is an alias of `except` supported by SingleStore.\n *\n * @example\n *\n * ```ts\n * // Select all courses offered in department A but not in department B\n * import { minus } from 'drizzle-orm/singlestore-core'\n *\n * await minus(\n * db.select({ courseName: depA.courseName }).from(depA),\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * // or\n * await db.select({ courseName: depA.courseName })\n * .from(depA)\n * .minus(\n * db.select({ courseName: depB.courseName }).from(depB)\n * );\n * ```\n */\nexport const minus = createSetOperator('except', true);\n"],"mappings":"AAAA,SAAS,YAAY,UAAU;AAC/B,SAAS,yBAAyB;AAWlC,SAAS,oBAAoB;AAC7B,SAAS,6BAA6B;AAWtC,SAAS,WAAW;AACpB,SAAS,gBAAgB;AACzB,SAAS,aAAa;AACtB;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAqBA,MAAM,yBAIX;AAAA,EACD,QAAiB,UAAU,IAAY;AAAA,EAE/B;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAuB,CAAC;AAAA,EACxB;AAAA,EAER,YACC,QAOC;AACD,SAAK,SAAS,OAAO;AACrB,SAAK,UAAU,OAAO;AACtB,SAAK,UAAU,OAAO;AACtB,QAAI,OAAO,UAAU;AACpB,WAAK,WAAW,OAAO;AAAA,IACxB;AACA,SAAK,WAAW,OAAO;AAAA,EACxB;AAAA,EAEA,KACC,QAOC;AACD,UAAM,kBAAkB,CAAC,CAAC,KAAK;AAE/B,QAAI;AACJ,QAAI,KAAK,QAAQ;AAChB,eAAS,KAAK;AAAA,IACf,WAAW,GAAG,QAAQ,QAAQ,GAAG;AAEhC,eAAS,OAAO;AAAA,QACf,OAAO,KAAK,OAAO,EAAE,cAAc,EAAE,IAAI,CACxC,QACI,CAAC,KAAK,OAAO,GAAqC,CAAsC,CAAC;AA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IAAI;AA2BhD,MAAM,YAAY,kBAAkB,aAAa,KAAK;AA2BtD,MAAM,SAAS,kBAAkB,UAAU,KAAK;AAyBhD,MAAM,QAAQ,kBAAkB,UAAU,IAAI;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/singlestore-core/query-builders/select.types.ts"],"sourcesContent":["import type {\n\tSelectedFields as SelectedFieldsBase,\n\tSelectedFieldsFlat as SelectedFieldsFlatBase,\n\tSelectedFieldsOrdered as SelectedFieldsOrderedBase,\n} from '~/operations.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tAppendToNullabilityMap,\n\tAppendToResult,\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tJoinNullability,\n\tJoinType,\n\tMapColumnsToTableAlias,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport type { SingleStoreColumn } from '~/singlestore-core/columns/index.ts';\nimport type { SingleStoreTable, SingleStoreTableWithColumns } from '~/singlestore-core/table.ts';\nimport type { ColumnsSelection, Placeholder, SQL, View } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { Table, UpdateTableConfig } from '~/table.ts';\nimport type { Assume, ValidateShape } from '~/utils.ts';\nimport type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig } from '../session.ts';\n/* import type { SingleStoreViewBase } from '../view-base.ts'; */\n/* import type { SingleStoreViewWithSelection } from '../view.ts'; */\nimport type { SingleStoreSelectBase, SingleStoreSelectQueryBuilderBase } from './select.ts';\n\nexport interface SingleStoreSelectJoinConfig {\n\ton: SQL | undefined;\n\ttable: SingleStoreTable | Subquery | SQL; // SingleStoreViewBase |\n\talias: string | undefined;\n\tjoinType: JoinType;\n\tlateral?: boolean;\n}\n\nexport type BuildAliasTable<TTable extends SingleStoreTable | View, TAlias extends string> = TTable extends Table\n\t? SingleStoreTableWithColumns<\n\t\tUpdateTableConfig<TTable['_']['config'], {\n\t\t\tname: TAlias;\n\t\t\tcolumns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias, 'singlestore'>;\n\t\t}>\n\t>\n\t/* : TTable extends View ? SingleStoreViewWithSelection<\n\t\t\tTAlias,\n\t\t\tTTable['_']['existing'],\n\t\t\tMapColumnsToTableAlias<TTable['_']['selectedFields'], TAlias, 'singlestore'>\n\t\t> */\n\t: never;\n\nexport interface SingleStoreSelectConfig {\n\twithList?: Subquery[];\n\tfields: Record<string, unknown>;\n\tfieldsFlat?: SelectedFieldsOrdered;\n\twhere?: SQL;\n\thaving?: SQL;\n\ttable: SingleStoreTable | Subquery | SQL; // | SingleStoreViewBase\n\tlimit?: number | Placeholder;\n\toffset?: number | Placeholder;\n\tjoins?: SingleStoreSelectJoinConfig[];\n\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tgroupBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tlockingClause?: {\n\t\tstrength: LockStrength;\n\t\tconfig: LockConfig;\n\t};\n\tdistinct?: boolean;\n\tsetOperators: {\n\t\trightSelect: TypedQueryBuilder<any, any>;\n\t\ttype: SetOperator;\n\t\tisAll: boolean;\n\t\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\t\tlimit?: number | Placeholder;\n\t\toffset?: number | Placeholder;\n\t}[];\n}\n\nexport type SingleStoreJoin<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n\tTJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\tTJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,\n> = T extends any ? SingleStoreSelectWithout<\n\t\tSingleStoreSelectKind<\n\t\t\tT['_']['hkt'],\n\t\t\tT['_']['tableName'],\n\t\t\tAppendToResult<\n\t\t\t\tT['_']['tableName'],\n\t\t\t\tT['_']['selection'],\n\t\t\t\tTJoinedName,\n\t\t\t\tTJoinedTable extends SingleStoreTable ? TJoinedTable['_']['columns']\n\t\t\t\t\t: TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>\n\t\t\t\t\t: never,\n\t\t\t\tT['_']['selectMode']\n\t\t\t>,\n\t\t\tT['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple',\n\t\t\tT['_']['preparedQueryHKT'],\n\t\t\tAppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>,\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods']\n\t\t>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>\n\t: never;\n\nexport type SingleStoreJoinFn<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n> = <\n\tTJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\tTJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,\n>(\n\ttable: TJoinedTable,\n\ton: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,\n) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;\n\nexport type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;\n\nexport type SelectedFields = SelectedFieldsBase<SingleStoreColumn, SingleStoreTable>;\n\nexport type SelectedFieldsOrdered = SelectedFieldsOrderedBase<SingleStoreColumn>;\n\nexport type LockStrength = 'update' | 'share';\n\nexport type LockConfig = {\n\tnoWait: true;\n\tskipLocked?: undefined;\n} | {\n\tnoWait?: undefined;\n\tskipLocked: true;\n} | {\n\tnoWait?: undefined;\n\tskipLocked?: undefined;\n};\n\nexport interface SingleStoreSelectHKTBase {\n\ttableName: string | undefined;\n\tselection: unknown;\n\tselectMode: SelectMode;\n\tpreparedQueryHKT: unknown;\n\tnullabilityMap: unknown;\n\tdynamic: boolean;\n\texcludedMethods: string;\n\tresult: unknown;\n\tselectedFields: unknown;\n\t_type: unknown;\n}\n\nexport type SingleStoreSelectKind<\n\tT extends SingleStoreSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability>,\n\tTDynamic extends boolean,\n\tTExcludedMethods extends string,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> = (T & {\n\ttableName: TTableName;\n\tselection: TSelection;\n\tselectMode: TSelectMode;\n\tpreparedQueryHKT: TPreparedQueryHKT;\n\tnullabilityMap: TNullabilityMap;\n\tdynamic: TDynamic;\n\texcludedMethods: TExcludedMethods;\n\tresult: TResult;\n\tselectedFields: TSelectedFields;\n})['_type'];\n\nexport interface SingleStoreSelectQueryBuilderHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tthis['tableName'],\n\t\tAssume<this['selection'], ColumnsSelection>,\n\t\tthis['selectMode'],\n\t\tAssume<this['preparedQueryHKT'], PreparedQueryHKTBase>,\n\t\tAssume<this['nullabilityMap'], Record<string, JoinNullability>>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume<this['result'], any[]>,\n\t\tAssume<this['selectedFields'], ColumnsSelection>\n\t>;\n}\n\nexport interface SingleStoreSelectHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectBase<\n\t\tthis['tableName'],\n\t\tAssume<this['selection'], ColumnsSelection>,\n\t\tthis['selectMode'],\n\t\tAssume<this['preparedQueryHKT'], PreparedQueryHKTBase>,\n\t\tAssume<this['nullabilityMap'], Record<string, JoinNullability>>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume<this['result'], any[]>,\n\t\tAssume<this['selectedFields'], ColumnsSelection>\n\t>;\n}\n\nexport type SingleStoreSetOperatorExcludedMethods =\n\t| 'where'\n\t| 'having'\n\t| 'groupBy'\n\t| 'session'\n\t| 'leftJoin'\n\t| 'rightJoin'\n\t| 'innerJoin'\n\t| 'fullJoin'\n\t| 'for';\n\nexport type SingleStoreSelectWithout<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n\tTResetExcluded extends boolean = false,\n> = TDynamic extends true ? T : Omit<\n\tSingleStoreSelectKind<\n\t\tT['_']['hkt'],\n\t\tT['_']['tableName'],\n\t\tT['_']['selection'],\n\t\tT['_']['selectMode'],\n\t\tT['_']['preparedQueryHKT'],\n\t\tT['_']['nullabilityMap'],\n\t\tTDynamic,\n\t\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K,\n\t\tT['_']['result'],\n\t\tT['_']['selectedFields']\n\t>,\n\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K\n>;\n\nexport type SingleStoreSelectPrepare<T extends AnySingleStoreSelect> = PreparedQueryKind<\n\tT['_']['preparedQueryHKT'],\n\tSingleStorePreparedQueryConfig & {\n\t\texecute: T['_']['result'];\n\t\titerator: T['_']['result'][number];\n\t},\n\ttrue\n>;\n\nexport type SingleStoreSelectDynamic<T extends AnySingleStoreSelectQueryBuilder> = SingleStoreSelectKind<\n\tT['_']['hkt'],\n\tT['_']['tableName'],\n\tT['_']['selection'],\n\tT['_']['selectMode'],\n\tT['_']['preparedQueryHKT'],\n\tT['_']['nullabilityMap'],\n\ttrue,\n\tnever,\n\tT['_']['result'],\n\tT['_']['selectedFields']\n>;\n\nexport type CreateSingleStoreSelectFromBuilderMode<\n\tTBuilderMode extends 'db' | 'qb',\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n> = TBuilderMode extends 'db' ? SingleStoreSelectBase<TTableName, TSelection, TSelectMode, TPreparedQueryHKT>\n\t: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT\n\t>;\n\nexport type SingleStoreSelectQueryBuilder<\n\tTHKT extends SingleStoreSelectHKTBase = SingleStoreSelectQueryBuilderHKT,\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = ColumnsSelection,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n\tTResult extends any[] = unknown[],\n\tTSelectedFields extends ColumnsSelection = ColumnsSelection,\n> = SingleStoreSelectQueryBuilderBase<\n\tTHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tnever,\n\tTResult,\n\tTSelectedFields\n>;\n\nexport type AnySingleStoreSelectQueryBuilder = SingleStoreSelectQueryBuilderBase<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport type AnySingleStoreSetOperatorInterface = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport interface SingleStoreSetOperatorInterface<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> {\n\t_: {\n\t\treadonly hkt: SingleStoreSelectHKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n}\n\nexport type SingleStoreSetOperatorWithResult<TResult extends any[]> = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tTResult,\n\tany\n>;\n\nexport type SingleStoreSelect<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record<string, any>,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n> = SingleStoreSelectBase<TTableName, TSelection, TSelectMode, PreparedQueryHKTBase, TNullabilityMap, true, never>;\n\nexport type AnySingleStoreSelect = SingleStoreSelectBase<any, any, any, any, any, any, any, any>;\n\nexport type SingleStoreSetOperator<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record<string, any>,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n> = SingleStoreSelectBase<\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tSingleStoreSetOperatorExcludedMethods\n>;\n\nexport type SetOperatorRightSelect<\n\tTValue extends SingleStoreSetOperatorWithResult<TResult>,\n\tTResult extends any[],\n> = TValue extends SingleStoreSetOperatorInterface<any, any, any, any, any, any, any, infer TValueResult, any>\n\t? ValidateShape<\n\t\tTValueResult[number],\n\t\tTResult[number],\n\t\tTypedQueryBuilder<any, TValueResult>\n\t>\n\t: TValue;\n\nexport type SetOperatorRestSelect<\n\tTValue extends readonly SingleStoreSetOperatorWithResult<TResult>[],\n\tTResult extends any[],\n> = TValue extends [infer First, ...infer Rest]\n\t? First extends SingleStoreSetOperatorInterface<any, any, any, any, any, any, any, infer TValueResult, any>\n\t\t? Rest extends AnySingleStoreSetOperatorInterface[] ? [\n\t\t\t\tValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>>,\n\t\t\t\t...SetOperatorRestSelect<Rest, TResult>,\n\t\t\t]\n\t\t: ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>[]>\n\t: never\n\t: TValue;\n\nexport type SingleStoreCreateSetOperatorFn = <\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTValue extends SingleStoreSetOperatorWithResult<TResult>,\n\tTRest extends SingleStoreSetOperatorWithResult<TResult>[],\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n>(\n\tleftSelect: SingleStoreSetOperatorInterface<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\trightSelect: SetOperatorRightSelect<TValue, TResult>,\n\t...restSelects: SetOperatorRestSelect<TRest, TResult>\n) => SingleStoreSelectWithout<\n\tSingleStoreSelectBase<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tfalse,\n\tSingleStoreSetOperatorExcludedMethods,\n\ttrue\n>;\n\nexport type GetSingleStoreSetOperators = {\n\tunion: SingleStoreCreateSetOperatorFn;\n\tintersect: SingleStoreCreateSetOperatorFn;\n\texcept: SingleStoreCreateSetOperatorFn;\n\tunionAll: SingleStoreCreateSetOperatorFn;\n\tminus: SingleStoreCreateSetOperatorFn;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../src/singlestore-core/query-builders/select.types.ts"],"sourcesContent":["import type {\n\tSelectedFields as SelectedFieldsBase,\n\tSelectedFieldsFlat as SelectedFieldsFlatBase,\n\tSelectedFieldsOrdered as SelectedFieldsOrderedBase,\n} from '~/operations.ts';\nimport type { TypedQueryBuilder } from '~/query-builders/query-builder.ts';\nimport type {\n\tAppendToNullabilityMap,\n\tAppendToResult,\n\tBuildSubquerySelection,\n\tGetSelectTableName,\n\tJoinNullability,\n\tJoinType,\n\tMapColumnsToTableAlias,\n\tSelectMode,\n\tSelectResult,\n\tSetOperator,\n} from '~/query-builders/select.types.ts';\nimport type { SingleStoreColumn } from '~/singlestore-core/columns/index.ts';\nimport type { SingleStoreTable, SingleStoreTableWithColumns } from '~/singlestore-core/table.ts';\nimport type { ColumnsSelection, Placeholder, SQL, View } from '~/sql/sql.ts';\nimport type { Subquery } from '~/subquery.ts';\nimport type { Table, UpdateTableConfig } from '~/table.ts';\nimport type { Assume, ValidateShape } from '~/utils.ts';\nimport type { PreparedQueryHKTBase, PreparedQueryKind, SingleStorePreparedQueryConfig } from '../session.ts';\n/* import type { SingleStoreViewBase } from '../view-base.ts'; */\n/* import type { SingleStoreViewWithSelection } from '../view.ts'; */\nimport type { SingleStoreSelectBase, SingleStoreSelectQueryBuilderBase } from './select.ts';\n\nexport interface SingleStoreSelectJoinConfig {\n\ton: SQL | undefined;\n\ttable: SingleStoreTable | Subquery | SQL; // SingleStoreViewBase |\n\talias: string | undefined;\n\tjoinType: JoinType;\n\tlateral?: boolean;\n}\n\nexport type BuildAliasTable<TTable extends SingleStoreTable | View, TAlias extends string> = TTable extends Table\n\t? SingleStoreTableWithColumns<\n\t\tUpdateTableConfig<TTable['_']['config'], {\n\t\t\tname: TAlias;\n\t\t\tcolumns: MapColumnsToTableAlias<TTable['_']['columns'], TAlias, 'singlestore'>;\n\t\t}>\n\t>\n\t/* : TTable extends View ? SingleStoreViewWithSelection<\n\t\t\tTAlias,\n\t\t\tTTable['_']['existing'],\n\t\t\tMapColumnsToTableAlias<TTable['_']['selectedFields'], TAlias, 'singlestore'>\n\t\t> */\n\t: never;\n\nexport interface SingleStoreSelectConfig {\n\twithList?: Subquery[];\n\tfields: Record<string, unknown>;\n\tfieldsFlat?: SelectedFieldsOrdered;\n\twhere?: SQL;\n\thaving?: SQL;\n\ttable: SingleStoreTable | Subquery | SQL; // | SingleStoreViewBase\n\tlimit?: number | Placeholder;\n\toffset?: number | Placeholder;\n\tjoins?: SingleStoreSelectJoinConfig[];\n\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tgroupBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\tlockingClause?: {\n\t\tstrength: LockStrength;\n\t\tconfig: LockConfig;\n\t};\n\tdistinct?: boolean;\n\tsetOperators: {\n\t\trightSelect: TypedQueryBuilder<any, any>;\n\t\ttype: SetOperator;\n\t\tisAll: boolean;\n\t\torderBy?: (SingleStoreColumn | SQL | SQL.Aliased)[];\n\t\tlimit?: number | Placeholder;\n\t\toffset?: number | Placeholder;\n\t}[];\n}\n\nexport type SingleStoreJoin<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n\tTJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase\n\tTJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,\n> = T extends any ? SingleStoreSelectWithout<\n\t\tSingleStoreSelectKind<\n\t\t\tT['_']['hkt'],\n\t\t\tT['_']['tableName'],\n\t\t\tAppendToResult<\n\t\t\t\tT['_']['tableName'],\n\t\t\t\tT['_']['selection'],\n\t\t\t\tTJoinedName,\n\t\t\t\tTJoinedTable extends SingleStoreTable ? TJoinedTable['_']['columns']\n\t\t\t\t\t: TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields>\n\t\t\t\t\t: never,\n\t\t\t\tT['_']['selectMode']\n\t\t\t>,\n\t\t\tT['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple',\n\t\t\tT['_']['preparedQueryHKT'],\n\t\t\tAppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>,\n\t\t\tTDynamic,\n\t\t\tT['_']['excludedMethods']\n\t\t>,\n\t\tTDynamic,\n\t\tT['_']['excludedMethods']\n\t>\n\t: never;\n\nexport type SingleStoreJoinFn<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tTJoinType extends JoinType,\n\tTIsLateral extends boolean,\n> = 'cross' extends TJoinType ? <\n\t\tTJoinedTable extends (TIsLateral extends true ? Subquery | SQL\n\t\t\t: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),\n\t\tTJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,\n\t>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>\n\t: <\n\t\tTJoinedTable extends (TIsLateral extends true ? Subquery | SQL\n\t\t\t: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),\n\t\tTJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,\n\t>(\n\t\ttable: TJoinedTable,\n\t\ton: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,\n\t) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;\n\nexport type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;\n\nexport type SelectedFields = SelectedFieldsBase<SingleStoreColumn, SingleStoreTable>;\n\nexport type SelectedFieldsOrdered = SelectedFieldsOrderedBase<SingleStoreColumn>;\n\nexport type LockStrength = 'update' | 'share';\n\nexport type LockConfig = {\n\tnoWait: true;\n\tskipLocked?: undefined;\n} | {\n\tnoWait?: undefined;\n\tskipLocked: true;\n} | {\n\tnoWait?: undefined;\n\tskipLocked?: undefined;\n};\n\nexport interface SingleStoreSelectHKTBase {\n\ttableName: string | undefined;\n\tselection: unknown;\n\tselectMode: SelectMode;\n\tpreparedQueryHKT: unknown;\n\tnullabilityMap: unknown;\n\tdynamic: boolean;\n\texcludedMethods: string;\n\tresult: unknown;\n\tselectedFields: unknown;\n\t_type: unknown;\n}\n\nexport type SingleStoreSelectKind<\n\tT extends SingleStoreSelectHKTBase,\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability>,\n\tTDynamic extends boolean,\n\tTExcludedMethods extends string,\n\tTResult = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> = (T & {\n\ttableName: TTableName;\n\tselection: TSelection;\n\tselectMode: TSelectMode;\n\tpreparedQueryHKT: TPreparedQueryHKT;\n\tnullabilityMap: TNullabilityMap;\n\tdynamic: TDynamic;\n\texcludedMethods: TExcludedMethods;\n\tresult: TResult;\n\tselectedFields: TSelectedFields;\n})['_type'];\n\nexport interface SingleStoreSelectQueryBuilderHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tthis['tableName'],\n\t\tAssume<this['selection'], ColumnsSelection>,\n\t\tthis['selectMode'],\n\t\tAssume<this['preparedQueryHKT'], PreparedQueryHKTBase>,\n\t\tAssume<this['nullabilityMap'], Record<string, JoinNullability>>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume<this['result'], any[]>,\n\t\tAssume<this['selectedFields'], ColumnsSelection>\n\t>;\n}\n\nexport interface SingleStoreSelectHKT extends SingleStoreSelectHKTBase {\n\t_type: SingleStoreSelectBase<\n\t\tthis['tableName'],\n\t\tAssume<this['selection'], ColumnsSelection>,\n\t\tthis['selectMode'],\n\t\tAssume<this['preparedQueryHKT'], PreparedQueryHKTBase>,\n\t\tAssume<this['nullabilityMap'], Record<string, JoinNullability>>,\n\t\tthis['dynamic'],\n\t\tthis['excludedMethods'],\n\t\tAssume<this['result'], any[]>,\n\t\tAssume<this['selectedFields'], ColumnsSelection>\n\t>;\n}\n\nexport type SingleStoreSetOperatorExcludedMethods =\n\t| 'where'\n\t| 'having'\n\t| 'groupBy'\n\t| 'session'\n\t| 'leftJoin'\n\t| 'rightJoin'\n\t| 'innerJoin'\n\t| 'fullJoin'\n\t| 'for';\n\nexport type SingleStoreSelectWithout<\n\tT extends AnySingleStoreSelectQueryBuilder,\n\tTDynamic extends boolean,\n\tK extends keyof T & string,\n\tTResetExcluded extends boolean = false,\n> = TDynamic extends true ? T : Omit<\n\tSingleStoreSelectKind<\n\t\tT['_']['hkt'],\n\t\tT['_']['tableName'],\n\t\tT['_']['selection'],\n\t\tT['_']['selectMode'],\n\t\tT['_']['preparedQueryHKT'],\n\t\tT['_']['nullabilityMap'],\n\t\tTDynamic,\n\t\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K,\n\t\tT['_']['result'],\n\t\tT['_']['selectedFields']\n\t>,\n\tTResetExcluded extends true ? K : T['_']['excludedMethods'] | K\n>;\n\nexport type SingleStoreSelectPrepare<T extends AnySingleStoreSelect> = PreparedQueryKind<\n\tT['_']['preparedQueryHKT'],\n\tSingleStorePreparedQueryConfig & {\n\t\texecute: T['_']['result'];\n\t\titerator: T['_']['result'][number];\n\t},\n\ttrue\n>;\n\nexport type SingleStoreSelectDynamic<T extends AnySingleStoreSelectQueryBuilder> = SingleStoreSelectKind<\n\tT['_']['hkt'],\n\tT['_']['tableName'],\n\tT['_']['selection'],\n\tT['_']['selectMode'],\n\tT['_']['preparedQueryHKT'],\n\tT['_']['nullabilityMap'],\n\ttrue,\n\tnever,\n\tT['_']['result'],\n\tT['_']['selectedFields']\n>;\n\nexport type CreateSingleStoreSelectFromBuilderMode<\n\tTBuilderMode extends 'db' | 'qb',\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase,\n> = TBuilderMode extends 'db' ? SingleStoreSelectBase<TTableName, TSelection, TSelectMode, TPreparedQueryHKT>\n\t: SingleStoreSelectQueryBuilderBase<\n\t\tSingleStoreSelectQueryBuilderHKT,\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT\n\t>;\n\nexport type SingleStoreSelectQueryBuilder<\n\tTHKT extends SingleStoreSelectHKTBase = SingleStoreSelectQueryBuilderHKT,\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = ColumnsSelection,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n\tTResult extends any[] = unknown[],\n\tTSelectedFields extends ColumnsSelection = ColumnsSelection,\n> = SingleStoreSelectQueryBuilderBase<\n\tTHKT,\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tnever,\n\tTResult,\n\tTSelectedFields\n>;\n\nexport type AnySingleStoreSelectQueryBuilder = SingleStoreSelectQueryBuilderBase<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport type AnySingleStoreSetOperatorInterface = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany\n>;\n\nexport interface SingleStoreSetOperatorInterface<\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n> {\n\t_: {\n\t\treadonly hkt: SingleStoreSelectHKT;\n\t\treadonly tableName: TTableName;\n\t\treadonly selection: TSelection;\n\t\treadonly selectMode: TSelectMode;\n\t\treadonly preparedQueryHKT: TPreparedQueryHKT;\n\t\treadonly nullabilityMap: TNullabilityMap;\n\t\treadonly dynamic: TDynamic;\n\t\treadonly excludedMethods: TExcludedMethods;\n\t\treadonly result: TResult;\n\t\treadonly selectedFields: TSelectedFields;\n\t};\n}\n\nexport type SingleStoreSetOperatorWithResult<TResult extends any[]> = SingleStoreSetOperatorInterface<\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tany,\n\tTResult,\n\tany\n>;\n\nexport type SingleStoreSelect<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record<string, any>,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n> = SingleStoreSelectBase<TTableName, TSelection, TSelectMode, PreparedQueryHKTBase, TNullabilityMap, true, never>;\n\nexport type AnySingleStoreSelect = SingleStoreSelectBase<any, any, any, any, any, any, any, any>;\n\nexport type SingleStoreSetOperator<\n\tTTableName extends string | undefined = string | undefined,\n\tTSelection extends ColumnsSelection = Record<string, any>,\n\tTSelectMode extends SelectMode = SelectMode,\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = Record<string, JoinNullability>,\n> = SingleStoreSelectBase<\n\tTTableName,\n\tTSelection,\n\tTSelectMode,\n\tTPreparedQueryHKT,\n\tTNullabilityMap,\n\ttrue,\n\tSingleStoreSetOperatorExcludedMethods\n>;\n\nexport type SetOperatorRightSelect<\n\tTValue extends SingleStoreSetOperatorWithResult<TResult>,\n\tTResult extends any[],\n> = TValue extends SingleStoreSetOperatorInterface<any, any, any, any, any, any, any, infer TValueResult, any>\n\t? ValidateShape<\n\t\tTValueResult[number],\n\t\tTResult[number],\n\t\tTypedQueryBuilder<any, TValueResult>\n\t>\n\t: TValue;\n\nexport type SetOperatorRestSelect<\n\tTValue extends readonly SingleStoreSetOperatorWithResult<TResult>[],\n\tTResult extends any[],\n> = TValue extends [infer First, ...infer Rest]\n\t? First extends SingleStoreSetOperatorInterface<any, any, any, any, any, any, any, infer TValueResult, any>\n\t\t? Rest extends AnySingleStoreSetOperatorInterface[] ? [\n\t\t\t\tValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>>,\n\t\t\t\t...SetOperatorRestSelect<Rest, TResult>,\n\t\t\t]\n\t\t: ValidateShape<TValueResult[number], TResult[number], TypedQueryBuilder<any, TValueResult>[]>\n\t: never\n\t: TValue;\n\nexport type SingleStoreCreateSetOperatorFn = <\n\tTTableName extends string | undefined,\n\tTSelection extends ColumnsSelection,\n\tTSelectMode extends SelectMode,\n\tTValue extends SingleStoreSetOperatorWithResult<TResult>,\n\tTRest extends SingleStoreSetOperatorWithResult<TResult>[],\n\tTPreparedQueryHKT extends PreparedQueryHKTBase = PreparedQueryHKTBase,\n\tTNullabilityMap extends Record<string, JoinNullability> = TTableName extends string ? Record<TTableName, 'not-null'>\n\t\t: {},\n\tTDynamic extends boolean = false,\n\tTExcludedMethods extends string = never,\n\tTResult extends any[] = SelectResult<TSelection, TSelectMode, TNullabilityMap>[],\n\tTSelectedFields extends ColumnsSelection = BuildSubquerySelection<TSelection, TNullabilityMap>,\n>(\n\tleftSelect: SingleStoreSetOperatorInterface<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\trightSelect: SetOperatorRightSelect<TValue, TResult>,\n\t...restSelects: SetOperatorRestSelect<TRest, TResult>\n) => SingleStoreSelectWithout<\n\tSingleStoreSelectBase<\n\t\tTTableName,\n\t\tTSelection,\n\t\tTSelectMode,\n\t\tTPreparedQueryHKT,\n\t\tTNullabilityMap,\n\t\tTDynamic,\n\t\tTExcludedMethods,\n\t\tTResult,\n\t\tTSelectedFields\n\t>,\n\tfalse,\n\tSingleStoreSetOperatorExcludedMethods,\n\ttrue\n>;\n\nexport type GetSingleStoreSetOperators = {\n\tunion: SingleStoreCreateSetOperatorFn;\n\tintersect: SingleStoreCreateSetOperatorFn;\n\texcept: SingleStoreCreateSetOperatorFn;\n\tunionAll: SingleStoreCreateSetOperatorFn;\n\tminus: SingleStoreCreateSetOperatorFn;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -48,8 +48,7 @@ export interface SingleStoreSelectConfig {
48
48
  }
49
49
  export type SingleStoreJoin<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
50
50
  TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>> = T extends any ? SingleStoreSelectWithout<SingleStoreSelectKind<T['_']['hkt'], T['_']['tableName'], AppendToResult<T['_']['tableName'], T['_']['selection'], TJoinedName, TJoinedTable extends SingleStoreTable ? TJoinedTable['_']['columns'] : TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields> : never, T['_']['selectMode']>, T['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple', T['_']['preparedQueryHKT'], AppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>, TDynamic, T['_']['excludedMethods']>, TDynamic, T['_']['excludedMethods']> : never;
51
- export type SingleStoreJoinFn<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType> = <TJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
52
- TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
51
+ export type SingleStoreJoinFn<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TIsLateral extends boolean> = 'cross' extends TJoinType ? <TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : SingleStoreTable | Subquery | SQL), TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName> : <TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : SingleStoreTable | Subquery | SQL), TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
53
52
  export type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;
54
53
  export type SelectedFields = SelectedFieldsBase<SingleStoreColumn, SingleStoreTable>;
55
54
  export type SelectedFieldsOrdered = SelectedFieldsOrderedBase<SingleStoreColumn>;
@@ -48,8 +48,7 @@ export interface SingleStoreSelectConfig {
48
48
  }
49
49
  export type SingleStoreJoin<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
50
50
  TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>> = T extends any ? SingleStoreSelectWithout<SingleStoreSelectKind<T['_']['hkt'], T['_']['tableName'], AppendToResult<T['_']['tableName'], T['_']['selection'], TJoinedName, TJoinedTable extends SingleStoreTable ? TJoinedTable['_']['columns'] : TJoinedTable extends Subquery ? Assume<TJoinedTable['_']['selectedFields'], SelectedFields> : never, T['_']['selectMode']>, T['_']['selectMode'] extends 'partial' ? T['_']['selectMode'] : 'multiple', T['_']['preparedQueryHKT'], AppendToNullabilityMap<T['_']['nullabilityMap'], TJoinedName, TJoinType>, TDynamic, T['_']['excludedMethods']>, TDynamic, T['_']['excludedMethods']> : never;
51
- export type SingleStoreJoinFn<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType> = <TJoinedTable extends SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
52
- TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
51
+ export type SingleStoreJoinFn<T extends AnySingleStoreSelectQueryBuilder, TDynamic extends boolean, TJoinType extends JoinType, TIsLateral extends boolean> = 'cross' extends TJoinType ? <TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : SingleStoreTable | Subquery | SQL), TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName> : <TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : SingleStoreTable | Subquery | SQL), TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>>(table: TJoinedTable, on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
53
52
  export type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;
54
53
  export type SelectedFields = SelectedFieldsBase<SingleStoreColumn, SingleStoreTable>;
55
54
  export type SelectedFieldsOrdered = SelectedFieldsOrderedBase<SingleStoreColumn>;
@@ -174,17 +174,18 @@ class SQLiteDialect {
174
174
  joinsArray.push(import_sql2.sql` `);
175
175
  }
176
176
  const table = joinMeta.table;
177
+ const onSql = joinMeta.on ? import_sql2.sql` on ${joinMeta.on}` : void 0;
177
178
  if ((0, import_entity.is)(table, import_table.SQLiteTable)) {
178
179
  const tableName = table[import_table.SQLiteTable.Symbol.Name];
179
180
  const tableSchema = table[import_table.SQLiteTable.Symbol.Schema];
180
181
  const origTableName = table[import_table.SQLiteTable.Symbol.OriginalName];
181
182
  const alias = tableName === origTableName ? void 0 : joinMeta.alias;
182
183
  joinsArray.push(
183
- import_sql2.sql`${import_sql2.sql.raw(joinMeta.joinType)} join ${tableSchema ? import_sql2.sql`${import_sql2.sql.identifier(tableSchema)}.` : void 0}${import_sql2.sql.identifier(origTableName)}${alias && import_sql2.sql` ${import_sql2.sql.identifier(alias)}`} on ${joinMeta.on}`
184
+ import_sql2.sql`${import_sql2.sql.raw(joinMeta.joinType)} join ${tableSchema ? import_sql2.sql`${import_sql2.sql.identifier(tableSchema)}.` : void 0}${import_sql2.sql.identifier(origTableName)}${alias && import_sql2.sql` ${import_sql2.sql.identifier(alias)}`}${onSql}`
184
185
  );
185
186
  } else {
186
187
  joinsArray.push(
187
- import_sql2.sql`${import_sql2.sql.raw(joinMeta.joinType)} join ${table} on ${joinMeta.on}`
188
+ import_sql2.sql`${import_sql2.sql.raw(joinMeta.joinType)} join ${table}${onSql}`
188
189
  );
189
190
  }
190
191
  if (index < joins.length - 1) {