Skip to content

Commit 50a8b16

Browse files
authored
Fixed type issues with joins with certain variations of tsconfig (fixes #4535, #4457) (#4603)
1 parent 9865e63 commit 50a8b16

File tree

21 files changed

+9727
-7530
lines changed

21 files changed

+9727
-7530
lines changed

changelogs/drizzle-orm/0.44.2.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- [BUG]: Fixed type issues with joins with certain variations of `tsconfig`: [#4535](https://github.com/drizzle-team/drizzle-orm/issues/4535), [#4457](https://github.com/drizzle-team/drizzle-orm/issues/4457)

drizzle-orm/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "drizzle-orm",
3-
"version": "0.44.1",
3+
"version": "0.44.2",
44
"description": "Drizzle ORM package for SQL databases",
55
"type": "module",
66
"scripts": {

drizzle-orm/src/gel-core/query-builders/select.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import type {
4141
CreateGelSelectFromBuilderMode,
4242
GelCreateSetOperatorFn,
4343
GelSelectConfig,
44+
GelSelectCrossJoinFn,
4445
GelSelectDynamic,
4546
GelSelectHKT,
4647
GelSelectHKTBase,
@@ -224,8 +225,10 @@ export abstract class GelSelectQueryBuilderBase<
224225
>(
225226
joinType: TJoinType,
226227
lateral: TIsLateral,
227-
): GelSelectJoinFn<this, TDynamic, TJoinType, TIsLateral> {
228-
return (
228+
): 'cross' extends TJoinType ? GelSelectCrossJoinFn<this, TDynamic, TIsLateral>
229+
: GelSelectJoinFn<this, TDynamic, TJoinType, TIsLateral>
230+
{
231+
return ((
229232
table: GelTable | Subquery | GelViewBase | SQL,
230233
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,
231234
) => {
@@ -300,7 +303,7 @@ export abstract class GelSelectQueryBuilderBase<
300303
}
301304

302305
return this as any;
303-
};
306+
}) as any;
304307
}
305308

306309
/**

drizzle-orm/src/gel-core/query-builders/select.types.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,22 @@ export type GelSelectJoinFn<
113113
TDynamic extends boolean,
114114
TJoinType extends JoinType,
115115
TIsLateral extends boolean,
116-
> = 'cross' extends TJoinType ? <
117-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
118-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
119-
>(table: TJoinedTable) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
120-
: <
121-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
122-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
123-
>(
124-
table: TJoinedTable,
125-
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
126-
) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
116+
> = <
117+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
118+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
119+
>(
120+
table: TJoinedTable,
121+
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
122+
) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
123+
124+
export type GelSelectCrossJoinFn<
125+
T extends AnyGelSelectQueryBuilder,
126+
TDynamic extends boolean,
127+
TIsLateral extends boolean,
128+
> = <
129+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
130+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
131+
>(table: TJoinedTable) => GelSelectJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;
127132

128133
export type SelectedFieldsFlat = SelectedFieldsFlatBase<GelColumn>;
129134

drizzle-orm/src/mysql-core/query-builders/select.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import type {
3434
LockConfig,
3535
LockStrength,
3636
MySqlCreateSetOperatorFn,
37+
MySqlCrossJoinFn,
3738
MySqlJoinFn,
3839
MySqlJoinType,
3940
MySqlSelectConfig,
@@ -237,7 +238,9 @@ export abstract class MySqlSelectQueryBuilderBase<
237238
>(
238239
joinType: TJoinType,
239240
lateral: TIsLateral,
240-
): MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral> {
241+
): 'cross' extends TJoinType ? MySqlCrossJoinFn<this, TDynamic, TIsLateral>
242+
: MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral>
243+
{
241244
return <
242245
TJoinedTable extends MySqlTable | Subquery | MySqlViewBase | SQL,
243246
>(

drizzle-orm/src/mysql-core/query-builders/select.types.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,27 +119,32 @@ export type MySqlJoinFn<
119119
TDynamic extends boolean,
120120
TJoinType extends MySqlJoinType,
121121
TIsLateral extends boolean,
122-
> = 'cross' extends TJoinType ? <
123-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
124-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
125-
>(
126-
table: TJoinedTable,
127-
onIndex?:
128-
| (TJoinedTable extends MySqlTable ? IndexConfig
129-
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
130-
| undefined,
131-
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
132-
: <
133-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
134-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
135-
>(
136-
table: TJoinedTable,
137-
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
138-
onIndex?:
139-
| (TJoinedTable extends MySqlTable ? IndexConfig
140-
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
141-
| undefined,
142-
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
122+
> = <
123+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
124+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
125+
>(
126+
table: TJoinedTable,
127+
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
128+
onIndex?:
129+
| (TJoinedTable extends MySqlTable ? IndexConfig
130+
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
131+
| undefined,
132+
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
133+
134+
export type MySqlCrossJoinFn<
135+
T extends AnyMySqlSelectQueryBuilder,
136+
TDynamic extends boolean,
137+
TIsLateral extends boolean,
138+
> = <
139+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
140+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
141+
>(
142+
table: TJoinedTable,
143+
onIndex?:
144+
| (TJoinedTable extends MySqlTable ? IndexConfig
145+
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
146+
| undefined,
147+
) => MySqlJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;
143148

144149
export type SelectedFieldsFlat = SelectedFieldsFlatBase<MySqlColumn>;
145150

drizzle-orm/src/pg-core/query-builders/select.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import type {
4545
LockStrength,
4646
PgCreateSetOperatorFn,
4747
PgSelectConfig,
48+
PgSelectCrossJoinFn,
4849
PgSelectDynamic,
4950
PgSelectHKT,
5051
PgSelectHKTBase,
@@ -231,7 +232,9 @@ export abstract class PgSelectQueryBuilderBase<
231232
>(
232233
joinType: TJoinType,
233234
lateral: TIsLateral,
234-
): PgSelectJoinFn<this, TDynamic, TJoinType, TIsLateral> {
235+
): 'cross' extends TJoinType ? PgSelectCrossJoinFn<this, TDynamic, TIsLateral>
236+
: PgSelectJoinFn<this, TDynamic, TJoinType, TIsLateral>
237+
{
235238
return ((
236239
table: TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL,
237240
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,

drizzle-orm/src/pg-core/query-builders/select.types.ts

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,30 @@ export type PgSelectJoinFn<
117117
TDynamic extends boolean,
118118
TJoinType extends JoinType,
119119
TIsLateral extends boolean,
120-
> = 'cross' extends TJoinType ? <
121-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
122-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
123-
>(
124-
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
125-
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
126-
>
127-
: TJoinedTable,
128-
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
129-
: <
130-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
131-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
132-
>(
133-
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
134-
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
135-
>
136-
: TJoinedTable,
137-
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
138-
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
120+
> = <
121+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
122+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
123+
>(
124+
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
125+
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
126+
>
127+
: TJoinedTable,
128+
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
129+
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
130+
131+
export type PgSelectCrossJoinFn<
132+
T extends AnyPgSelectQueryBuilder,
133+
TDynamic extends boolean,
134+
TIsLateral extends boolean,
135+
> = <
136+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
137+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
138+
>(
139+
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
140+
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
141+
>
142+
: TJoinedTable,
143+
) => PgSelectJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;
139144

140145
export type SelectedFieldsFlat = SelectedFieldsFlatBase<PgColumn>;
141146

drizzle-orm/src/singlestore-core/query-builders/select.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import type {
4444
SelectedFields,
4545
SetOperatorRightSelect,
4646
SingleStoreCreateSetOperatorFn,
47+
SingleStoreCrossJoinFn,
4748
SingleStoreJoinFn,
4849
SingleStoreSelectConfig,
4950
SingleStoreSelectDynamic,
@@ -210,7 +211,9 @@ export abstract class SingleStoreSelectQueryBuilderBase<
210211
>(
211212
joinType: TJoinType,
212213
lateral: TIsLateral,
213-
): SingleStoreJoinFn<this, TDynamic, TJoinType, TIsLateral> {
214+
): 'cross' extends TJoinType ? SingleStoreCrossJoinFn<this, TDynamic, TIsLateral>
215+
: SingleStoreJoinFn<this, TDynamic, TJoinType, TIsLateral>
216+
{
214217
return (
215218
table: SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
216219
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,

drizzle-orm/src/singlestore-core/query-builders/select.types.ts

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,24 @@ export type SingleStoreJoinFn<
111111
TDynamic extends boolean,
112112
TJoinType extends JoinType,
113113
TIsLateral extends boolean,
114-
> = 'cross' extends TJoinType ? <
115-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
116-
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
117-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
118-
>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
119-
: <
120-
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
121-
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
122-
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
123-
>(
124-
table: TJoinedTable,
125-
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
126-
) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
114+
> = <
115+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
116+
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
117+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
118+
>(
119+
table: TJoinedTable,
120+
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
121+
) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
122+
123+
export type SingleStoreCrossJoinFn<
124+
T extends AnySingleStoreSelectQueryBuilder,
125+
TDynamic extends boolean,
126+
TIsLateral extends boolean,
127+
> = <
128+
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
129+
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
130+
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
131+
>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;
127132

128133
export type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;
129134

0 commit comments

Comments
 (0)