From 5dc5b05fb6b4d6b7ba5ac25d99dc8d6bcd833ace Mon Sep 17 00:00:00 2001 From: Sukairo-02 Date: Wed, 11 Dec 2024 05:58:55 +0200 Subject: [PATCH] Added `| undefined` to optional fields in `insertModel`, `db.update().set()` args, rqb config to allow undefined to still be passed with `exactOptionalPropertyTypes` typescript flag set to `true` (issue #2742) --- .../src/mysql-core/query-builders/update.ts | 3 +- .../src/pg-core/query-builders/update.ts | 3 +- drizzle-orm/src/relations.ts | 43 +++++++++++-------- .../singlestore-core/query-builders/update.ts | 3 +- .../src/sqlite-core/query-builders/update.ts | 3 +- drizzle-orm/src/table.ts | 2 +- 6 files changed, 34 insertions(+), 23 deletions(-) diff --git a/drizzle-orm/src/mysql-core/query-builders/update.ts b/drizzle-orm/src/mysql-core/query-builders/update.ts index 9efc4e325..7c6fd40ab 100644 --- a/drizzle-orm/src/mysql-core/query-builders/update.ts +++ b/drizzle-orm/src/mysql-core/query-builders/update.ts @@ -34,7 +34,8 @@ export type MySqlUpdateSetSource = & { [Key in keyof TTable['$inferInsert']]?: | GetColumnData - | SQL; + | SQL + | undefined; } & {}; diff --git a/drizzle-orm/src/pg-core/query-builders/update.ts b/drizzle-orm/src/pg-core/query-builders/update.ts index c6d04ee35..911916381 100644 --- a/drizzle-orm/src/pg-core/query-builders/update.ts +++ b/drizzle-orm/src/pg-core/query-builders/update.ts @@ -53,7 +53,8 @@ export type PgUpdateSetSource = [Key in keyof TTable['$inferInsert']]?: | GetColumnData | SQL - | PgColumn; + | PgColumn + | undefined; } & {}; diff --git a/drizzle-orm/src/relations.ts b/drizzle-orm/src/relations.ts index ed49c138f..adaee8076 100644 --- a/drizzle-orm/src/relations.ts +++ b/drizzle-orm/src/relations.ts @@ -214,22 +214,27 @@ export type DBQueryConfig< TTableConfig extends TableRelationalConfig = TableRelationalConfig, > = & { - columns?: { - [K in keyof TTableConfig['columns']]?: boolean; - }; - with?: { - [K in keyof TTableConfig['relations']]?: - | true - | DBQueryConfig< - TTableConfig['relations'][K] extends One ? 'one' : 'many', - false, - TSchema, - FindTableByDBName< + columns?: + | { + [K in keyof TTableConfig['columns']]?: boolean; + } + | undefined; + with?: + | { + [K in keyof TTableConfig['relations']]?: + | true + | DBQueryConfig< + TTableConfig['relations'][K] extends One ? 'one' : 'many', + false, TSchema, - TTableConfig['relations'][K]['referencedTableName'] + FindTableByDBName< + TSchema, + TTableConfig['relations'][K]['referencedTableName'] + > > - >; - }; + | undefined; + } + | undefined; extras?: | Record | (( @@ -238,7 +243,8 @@ export type DBQueryConfig< : TTableConfig['columns'] >, operators: { sql: Operators['sql'] }, - ) => Record); + ) => Record) + | undefined; } & (TRelationType extends 'many' ? & { @@ -260,11 +266,12 @@ export type DBQueryConfig< : TTableConfig['columns'] >, operators: OrderByOperators, - ) => ValueOrArray); - limit?: number | Placeholder; + ) => ValueOrArray) + | undefined; + limit?: number | Placeholder | undefined; } & (TIsRoot extends true ? { - offset?: number | Placeholder; + offset?: number | Placeholder | undefined; } : {}) : {}); diff --git a/drizzle-orm/src/singlestore-core/query-builders/update.ts b/drizzle-orm/src/singlestore-core/query-builders/update.ts index 40ca97662..6a843373c 100644 --- a/drizzle-orm/src/singlestore-core/query-builders/update.ts +++ b/drizzle-orm/src/singlestore-core/query-builders/update.ts @@ -34,7 +34,8 @@ export type SingleStoreUpdateSetSource = & { [Key in keyof TTable['$inferInsert']]?: | GetColumnData - | SQL; + | SQL + | undefined; } & {}; diff --git a/drizzle-orm/src/sqlite-core/query-builders/update.ts b/drizzle-orm/src/sqlite-core/query-builders/update.ts index cc5e4ee30..6915d60a9 100644 --- a/drizzle-orm/src/sqlite-core/query-builders/update.ts +++ b/drizzle-orm/src/sqlite-core/query-builders/update.ts @@ -40,7 +40,8 @@ export type SQLiteUpdateSetSource = [Key in keyof TTable['$inferInsert']]?: | GetColumnData | SQL - | SQLiteColumn; + | SQLiteColumn + | undefined; } & {}; diff --git a/drizzle-orm/src/table.ts b/drizzle-orm/src/table.ts index c843fd519..5f6b0d679 100644 --- a/drizzle-orm/src/table.ts +++ b/drizzle-orm/src/table.ts @@ -174,7 +174,7 @@ export type InferModelFromColumns< TColumns[Key], TConfig['override'] > - ]?: GetColumnData; + ]?: GetColumnData | undefined; } : { [