From 947c2fd53fb928108ea1ba613f35b8efcdebc282 Mon Sep 17 00:00:00 2001 From: mertmit Date: Mon, 5 Dec 2022 21:52:01 +0300 Subject: [PATCH] fix: add useNullAsDefault flag for sqlite on root level Signed-off-by: mertmit --- .../nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts | 2 ++ .../nocodb/src/lib/db/sql-data-mapper/lib/sql/CustomKnex.ts | 5 +++++ packages/nocodb/src/lib/meta/MetaAPILogger.ts | 1 - packages/nocodb/src/lib/meta/NcMetaIOImpl.ts | 4 ---- packages/nocodb/src/lib/meta/api/projectApis.ts | 1 - packages/nocodb/src/lib/utils/NcConfigFactory.ts | 2 -- 6 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts b/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts index 115e5e7d03..ccced13ce2 100644 --- a/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts +++ b/packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts @@ -19,6 +19,8 @@ class SqliteClient extends KnexClient { private _version: any; constructor(connectionConfig) { + // sqlite does not support inserting default values and knex fires a warning without this flag + connectionConfig.connection.useNullAsDefault = true; super(connectionConfig); this.sqlClient = knex(connectionConfig.connection); this.queries = queries; diff --git a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/CustomKnex.ts b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/CustomKnex.ts index 526f954df6..b114d11526 100644 --- a/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/CustomKnex.ts +++ b/packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/CustomKnex.ts @@ -988,6 +988,11 @@ function parseNestedCondition(obj, qb, pKey?, table?, tableAlias?) { type CustomKnex = Knex; function CustomKnex(arg: string | Knex.Config | any): CustomKnex { + // sqlite does not support inserting default values and knex fires a warning without this flag + if (arg?.client === 'sqlite3') { + arg.useNullAsDefault = true; + } + const kn: any = knex(arg); const knexRaw = kn.raw; diff --git a/packages/nocodb/src/lib/meta/MetaAPILogger.ts b/packages/nocodb/src/lib/meta/MetaAPILogger.ts index 8531e96c44..88aac02eec 100644 --- a/packages/nocodb/src/lib/meta/MetaAPILogger.ts +++ b/packages/nocodb/src/lib/meta/MetaAPILogger.ts @@ -11,7 +11,6 @@ export default class MetaAPILogger { connection: { filename: 'noco_log.db', }, - useNullAsDefault: true, }); } diff --git a/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts b/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts index e2b3e87a0c..578afa059f 100644 --- a/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts +++ b/packages/nocodb/src/lib/meta/NcMetaIOImpl.ts @@ -77,10 +77,6 @@ export default class NcMetaIOImpl extends NcMetaIO { constructor(app: Noco, config: NcConfig, trx = null) { super(app, config); - if (this.config?.meta?.db?.client === 'sqlite3') { - this.config.meta.db.useNullAsDefault = true; - } - if (this.config?.meta?.db) { this.connection = trx || XKnex(this.config?.meta?.db); } else { diff --git a/packages/nocodb/src/lib/meta/api/projectApis.ts b/packages/nocodb/src/lib/meta/api/projectApis.ts index cafc073080..e2f07a1147 100644 --- a/packages/nocodb/src/lib/meta/api/projectApis.ts +++ b/packages/nocodb/src/lib/meta/api/projectApis.ts @@ -138,7 +138,6 @@ async function projectCreate(req: Request, res) { connection: { filename: `${toolDir}/nc_minimal_dbs/${projectTitle}_${dbId}.db`, }, - useNullAsDefault: true, }, }, inflection_column: 'camelize', diff --git a/packages/nocodb/src/lib/utils/NcConfigFactory.ts b/packages/nocodb/src/lib/utils/NcConfigFactory.ts index 75c7924475..7424b1b2ba 100644 --- a/packages/nocodb/src/lib/utils/NcConfigFactory.ts +++ b/packages/nocodb/src/lib/utils/NcConfigFactory.ts @@ -200,7 +200,6 @@ export default class NcConfigFactory implements NcConfig { }, database: url.searchParams.get('d') || url.searchParams.get('database'), - useNullAsDefault: true, }, } as any; } else { @@ -496,7 +495,6 @@ export default class NcConfigFactory implements NcConfig { connection: { ...dbConnectionConfig, database: dbConnectionConfig.connection.filename, - useNullAsDefault: true, }, }; }