Skip to content

Commit f0e4a3c

Browse files
committed
Fixed lack of type recalculations on dynamic pg updates with joins
1 parent a480556 commit f0e4a3c

File tree

1 file changed

+24
-19
lines changed
  • drizzle-orm/src/pg-core/query-builders

1 file changed

+24
-19
lines changed

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

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export type PgUpdateWithJoins<
122122
T extends AnyPgUpdate,
123123
TDynamic extends boolean,
124124
TFrom extends PgTable | Subquery | PgViewBase | SQL,
125-
> = TDynamic extends true ? T : Omit<
125+
> = Omit<
126126
PgUpdateKind<
127127
T['_']['hkt'],
128128
T['_']['table'],
@@ -137,9 +137,11 @@ export type PgUpdateWithJoins<
137137
table: TFrom;
138138
}],
139139
TDynamic,
140-
Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>
140+
TDynamic extends true ? never
141+
: Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>
141142
>,
142-
Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>
143+
TDynamic extends true ? never
144+
: Exclude<T['_']['excludedMethods'] | 'from', 'leftJoin' | 'rightJoin' | 'innerJoin' | 'fullJoin'>
143145
>;
144146

145147
export type PgUpdateJoinFn<
@@ -171,21 +173,24 @@ export type PgUpdateJoin<
171173
TDynamic extends boolean,
172174
TJoinType extends JoinType,
173175
TJoinedTable extends PgTable | Subquery | PgViewBase | SQL,
174-
> = TDynamic extends true ? T : PgUpdateKind<
175-
T['_']['hkt'],
176-
T['_']['table'],
177-
T['_']['queryResult'],
178-
T['_']['from'],
179-
T['_']['selectedFields'],
180-
T['_']['returning'],
181-
AppendToNullabilityMap<T['_']['nullabilityMap'], GetSelectTableName<TJoinedTable>, TJoinType>,
182-
[...T['_']['joins'], {
183-
name: GetSelectTableName<TJoinedTable>;
184-
joinType: TJoinType;
185-
table: TJoinedTable;
186-
}],
187-
TDynamic,
188-
T['_']['excludedMethods']
176+
> = Omit<
177+
PgUpdateKind<
178+
T['_']['hkt'],
179+
T['_']['table'],
180+
T['_']['queryResult'],
181+
T['_']['from'],
182+
T['_']['selectedFields'],
183+
T['_']['returning'],
184+
AppendToNullabilityMap<T['_']['nullabilityMap'], GetSelectTableName<TJoinedTable>, TJoinType>,
185+
[...T['_']['joins'], {
186+
name: GetSelectTableName<TJoinedTable>;
187+
joinType: TJoinType;
188+
table: TJoinedTable;
189+
}],
190+
TDynamic,
191+
TDynamic extends true ? never : T['_']['excludedMethods']
192+
>,
193+
TDynamic extends true ? never : T['_']['excludedMethods']
189194
>;
190195

191196
export type Join = {
@@ -330,7 +335,6 @@ export interface PgUpdateHKTBase {
330335
returning: unknown;
331336
dynamic: boolean;
332337
excludedMethods: string;
333-
result: unknown;
334338
_type: unknown;
335339
}
336340

@@ -370,6 +374,7 @@ export type PgUpdateKind<
370374
returning: TReturning;
371375
dynamic: TDynamic;
372376
excludedMethods: TExcludedMethods;
377+
result: TReturning extends undefined ? PgQueryResultKind<TQueryResult, never> : TReturning[];
373378
})['_type'];
374379

375380
export type AnyPgUpdate = PgUpdateBase<any, any, any, any, any, any, any, any, any, any>;

0 commit comments

Comments
 (0)