Skip to content
Merged

V0.44.2 #4603

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/drizzle-orm/0.44.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +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)
2 changes: 1 addition & 1 deletion drizzle-orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drizzle-orm",
"version": "0.44.1",
"version": "0.44.2",
"description": "Drizzle ORM package for SQL databases",
"type": "module",
"scripts": {
Expand Down
9 changes: 6 additions & 3 deletions drizzle-orm/src/gel-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import type {
CreateGelSelectFromBuilderMode,
GelCreateSetOperatorFn,
GelSelectConfig,
GelSelectCrossJoinFn,
GelSelectDynamic,
GelSelectHKT,
GelSelectHKTBase,
Expand Down Expand Up @@ -224,8 +225,10 @@ export abstract class GelSelectQueryBuilderBase<
>(
joinType: TJoinType,
lateral: TIsLateral,
): GelSelectJoinFn<this, TDynamic, TJoinType, TIsLateral> {
return (
): 'cross' extends TJoinType ? GelSelectCrossJoinFn<this, TDynamic, TIsLateral>
: GelSelectJoinFn<this, TDynamic, TJoinType, TIsLateral>
{
return ((
table: GelTable | Subquery | GelViewBase | SQL,
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,
) => {
Expand Down Expand Up @@ -300,7 +303,7 @@ export abstract class GelSelectQueryBuilderBase<
}

return this as any;
};
}) as any;
}

/**
Expand Down
27 changes: 16 additions & 11 deletions drizzle-orm/src/gel-core/query-builders/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,22 @@ export type GelSelectJoinFn<
TDynamic extends boolean,
TJoinType extends JoinType,
TIsLateral extends boolean,
> = 'cross' extends TJoinType ? <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
: <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => GelSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;

export type GelSelectCrossJoinFn<
T extends AnyGelSelectQueryBuilder,
TDynamic extends boolean,
TIsLateral extends boolean,
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : GelTable | Subquery | GelViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => GelSelectJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;

export type SelectedFieldsFlat = SelectedFieldsFlatBase<GelColumn>;

Expand Down
5 changes: 4 additions & 1 deletion drizzle-orm/src/mysql-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import type {
LockConfig,
LockStrength,
MySqlCreateSetOperatorFn,
MySqlCrossJoinFn,
MySqlJoinFn,
MySqlJoinType,
MySqlSelectConfig,
Expand Down Expand Up @@ -237,7 +238,9 @@ export abstract class MySqlSelectQueryBuilderBase<
>(
joinType: TJoinType,
lateral: TIsLateral,
): MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral> {
): 'cross' extends TJoinType ? MySqlCrossJoinFn<this, TDynamic, TIsLateral>
: MySqlJoinFn<this, TDynamic, TJoinType, TIsLateral>
{
return <
TJoinedTable extends MySqlTable | Subquery | MySqlViewBase | SQL,
>(
Expand Down
47 changes: 26 additions & 21 deletions drizzle-orm/src/mysql-core/query-builders/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,32 @@ export type MySqlJoinFn<
TDynamic extends boolean,
TJoinType extends MySqlJoinType,
TIsLateral extends boolean,
> = 'cross' extends TJoinType ? <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
onIndex?:
| (TJoinedTable extends MySqlTable ? IndexConfig
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
| undefined,
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
: <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
onIndex?:
| (TJoinedTable extends MySqlTable ? IndexConfig
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
| undefined,
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
onIndex?:
| (TJoinedTable extends MySqlTable ? IndexConfig
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
| undefined,
) => MySqlJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;

export type MySqlCrossJoinFn<
T extends AnyMySqlSelectQueryBuilder,
TDynamic extends boolean,
TIsLateral extends boolean,
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : MySqlTable | Subquery | MySqlViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
onIndex?:
| (TJoinedTable extends MySqlTable ? IndexConfig
: 'Index hint configuration is allowed only for MySqlTable and not for subqueries or views')
| undefined,
) => MySqlJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;

export type SelectedFieldsFlat = SelectedFieldsFlatBase<MySqlColumn>;

Expand Down
5 changes: 4 additions & 1 deletion drizzle-orm/src/pg-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import type {
LockStrength,
PgCreateSetOperatorFn,
PgSelectConfig,
PgSelectCrossJoinFn,
PgSelectDynamic,
PgSelectHKT,
PgSelectHKTBase,
Expand Down Expand Up @@ -231,7 +232,9 @@ export abstract class PgSelectQueryBuilderBase<
>(
joinType: TJoinType,
lateral: TIsLateral,
): PgSelectJoinFn<this, TDynamic, TJoinType, TIsLateral> {
): 'cross' extends TJoinType ? PgSelectCrossJoinFn<this, TDynamic, TIsLateral>
: PgSelectJoinFn<this, TDynamic, TJoinType, TIsLateral>
{
return ((
table: TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL,
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,
Expand Down
43 changes: 24 additions & 19 deletions drizzle-orm/src/pg-core/query-builders/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,25 +117,30 @@ export type PgSelectJoinFn<
TDynamic extends boolean,
TJoinType extends JoinType,
TIsLateral extends boolean,
> = 'cross' extends TJoinType ? <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
>
: TJoinedTable,
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
: <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
>
: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
>
: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => PgSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;

export type PgSelectCrossJoinFn<
T extends AnyPgSelectQueryBuilder,
TDynamic extends boolean,
TIsLateral extends boolean,
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL : PgTable | Subquery | PgViewBase | SQL),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TableLikeHasEmptySelection<TJoinedTable> extends true ? DrizzleTypeError<
"Cannot reference a data-modifying statement subquery if it doesn't contain a `returning` clause"
>
: TJoinedTable,
) => PgSelectJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;

export type SelectedFieldsFlat = SelectedFieldsFlatBase<PgColumn>;

Expand Down
5 changes: 4 additions & 1 deletion drizzle-orm/src/singlestore-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import type {
SelectedFields,
SetOperatorRightSelect,
SingleStoreCreateSetOperatorFn,
SingleStoreCrossJoinFn,
SingleStoreJoinFn,
SingleStoreSelectConfig,
SingleStoreSelectDynamic,
Expand Down Expand Up @@ -210,7 +211,9 @@ export abstract class SingleStoreSelectQueryBuilderBase<
>(
joinType: TJoinType,
lateral: TIsLateral,
): SingleStoreJoinFn<this, TDynamic, TJoinType, TIsLateral> {
): 'cross' extends TJoinType ? SingleStoreCrossJoinFn<this, TDynamic, TIsLateral>
: SingleStoreJoinFn<this, TDynamic, TJoinType, TIsLateral>
{
return (
table: SingleStoreTable | Subquery | SQL, // | SingleStoreViewBase
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,
Expand Down
31 changes: 18 additions & 13 deletions drizzle-orm/src/singlestore-core/query-builders/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,24 @@ export type SingleStoreJoinFn<
TDynamic extends boolean,
TJoinType extends JoinType,
TIsLateral extends boolean,
> = 'cross' extends TJoinType ? <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
: <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => SingleStoreJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;

export type SingleStoreCrossJoinFn<
T extends AnySingleStoreSelectQueryBuilder,
TDynamic extends boolean,
TIsLateral extends boolean,
> = <
TJoinedTable extends (TIsLateral extends true ? Subquery | SQL
: SingleStoreTable | Subquery | SQL /* | SingleStoreViewBase */),
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => SingleStoreJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;

export type SelectedFieldsFlat = SelectedFieldsFlatBase<SingleStoreColumn>;

Expand Down
5 changes: 4 additions & 1 deletion drizzle-orm/src/sqlite-core/query-builders/select.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import type {
SetOperatorRightSelect,
SQLiteCreateSetOperatorFn,
SQLiteSelectConfig,
SQLiteSelectCrossJoinFn,
SQLiteSelectDynamic,
SQLiteSelectExecute,
SQLiteSelectHKT,
Expand Down Expand Up @@ -205,7 +206,9 @@ export abstract class SQLiteSelectQueryBuilderBase<

private createJoin<TJoinType extends JoinType>(
joinType: TJoinType,
): SQLiteSelectJoinFn<this, TDynamic, TJoinType> {
): 'cross' extends TJoinType ? SQLiteSelectCrossJoinFn<this, TDynamic>
: SQLiteSelectJoinFn<this, TDynamic, TJoinType>
{
return (
table: SQLiteTable | Subquery | SQLiteViewBase | SQL,
on?: ((aliases: TSelection) => SQL | undefined) | SQL | undefined,
Expand Down
26 changes: 15 additions & 11 deletions drizzle-orm/src/sqlite-core/query-builders/select.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,21 @@ export type SQLiteSelectJoinFn<
T extends AnySQLiteSelectQueryBuilder,
TDynamic extends boolean,
TJoinType extends JoinType,
> = 'cross' extends TJoinType ? <
TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL,
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => SQLiteSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>
: <
TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL,
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => SQLiteSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;
> = <
TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL,
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(
table: TJoinedTable,
on: ((aliases: T['_']['selection']) => SQL | undefined) | SQL | undefined,
) => SQLiteSelectJoin<T, TDynamic, TJoinType, TJoinedTable, TJoinedName>;

export type SQLiteSelectCrossJoinFn<
T extends AnySQLiteSelectQueryBuilder,
TDynamic extends boolean,
> = <
TJoinedTable extends SQLiteTable | Subquery | SQLiteViewBase | SQL,
TJoinedName extends GetSelectTableName<TJoinedTable> = GetSelectTableName<TJoinedTable>,
>(table: TJoinedTable) => SQLiteSelectJoin<T, TDynamic, 'cross', TJoinedTable, TJoinedName>;

export type SelectedFieldsFlat = SelectFieldsFlatBase<SQLiteColumn>;

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "",
"type": "module",
"scripts": {
"test:types": "tsc",
"test:types": "tsc && cd type-tests/join-nodenext && tsc",
"test": "pnpm test:vitest",
"test:vitest": "vitest run --pass-with-no-tests",
"test:esm": "node tests/imports.test.mjs && node tests/imports.test.cjs",
Expand Down
39 changes: 39 additions & 0 deletions integration-tests/type-tests/join-nodenext/gel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { eq } from 'drizzle-orm';
import { drizzle } from 'drizzle-orm/gel';
import { gelTable, text, uuid } from 'drizzle-orm/gel-core';
import { expectTypeOf } from 'vitest';

const account = gelTable('accounts', {
id: uuid('id').primaryKey().notNull(),
userId: uuid('user_id')
.notNull()
.references(() => users.id),
meta: text().notNull(),
});

const users = gelTable('users', {
id: uuid('id').primaryKey(),
name: text('name').notNull(),
username: text('username').notNull().unique(),
});

const db = drizzle.mock();

(async () => {
const res = await db.select()
.from(users)
.innerJoin(account, eq(users.id, account.id));

expectTypeOf(res).toEqualTypeOf<{
accounts: {
id: string;
userId: string;
meta: string;
};
users: {
id: string;
name: string;
username: string;
};
}[]>();
});
Loading