Browse Source

fix(nocodb): remove mysqlConnectionTypeCastConfig

pull/5659/head
Wing-Kam Wong 1 year ago
parent
commit
9ed748929a
  1. 46
      packages/nocodb/src/utils/NcConfigFactory.ts

46
packages/nocodb/src/utils/NcConfigFactory.ts

@ -3,8 +3,6 @@ import { URL } from 'url';
import { promisify } from 'util'; import { promisify } from 'util';
import * as path from 'path'; import * as path from 'path';
import parseDbUrl from 'parse-database-url'; import parseDbUrl from 'parse-database-url';
import dayjs from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { SqlClientFactory } from '../db/sql-client/lib/SqlClientFactory'; import { SqlClientFactory } from '../db/sql-client/lib/SqlClientFactory';
// import SqlClientFactory from '../db/sql-client/lib/SqlClientFactory'; // import SqlClientFactory from '../db/sql-client/lib/SqlClientFactory';
// import type { // import type {
@ -21,8 +19,6 @@ import { SqlClientFactory } from '../db/sql-client/lib/SqlClientFactory';
// animals, // animals,
// } = require('unique-names-generator'); // } = require('unique-names-generator');
dayjs.extend(utc);
type NcConfig = any; type NcConfig = any;
type DbConfig = any; type DbConfig = any;
@ -240,11 +236,6 @@ export default class NcConfigFactory {
acquireConnectionTimeout: 600000, acquireConnectionTimeout: 600000,
} as any; } as any;
dbConfig.connection = this.addTypeCastConfig(
url.protocol,
dbConfig.connection,
);
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
dbConfig.connection.ssl = true; dbConfig.connection.ssl = true;
} }
@ -306,16 +297,6 @@ export default class NcConfigFactory {
.replace(/[ -]/g, '_');*/ .replace(/[ -]/g, '_');*/
} }
private static addTypeCastConfig(clientType: string, connection) {
if (clientType.startsWith('mysql')) {
connection = {
...connection,
...this.mysqlConnectionTypeCastConfig,
};
}
return connection;
}
static async metaUrlToDbConfig(urlString) { static async metaUrlToDbConfig(urlString) {
const url = new URL(urlString); const url = new URL(urlString);
@ -367,12 +348,6 @@ export default class NcConfigFactory {
} }
: {}), : {}),
}; };
dbConfig.connection = this.addTypeCastConfig(
url.protocol,
dbConfig.connection,
);
if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) { if (process.env.NODE_TLS_REJECT_UNAUTHORIZED) {
dbConfig.connection.ssl = true; dbConfig.connection.ssl = true;
} }
@ -536,11 +511,6 @@ export default class NcConfigFactory {
}; };
} }
dbConfig.connection = this.addTypeCastConfig(
dbConfig.client,
dbConfig.connection,
);
// todo: // todo:
const key = ''; const key = '';
Object.assign(dbConfig, { Object.assign(dbConfig, {
@ -774,22 +744,6 @@ export default class NcConfigFactory {
return res; return res;
} }
// mysql driver will cast mysql types into native JavaScript types by default
// hence we use typeCast to convert to the expected value (UTC) for date time fields
private static mysqlConnectionTypeCastConfig = {
typeCast: function (field, next) {
if (field.type === 'DATETIME' || field.type === 'TIMESTAMP') {
const d = dayjs(field.string());
if (!d.isValid()) {
return null;
}
return d.utc().format('YYYY-MM-DD HH:mm:ss');
}
return next();
},
timezone: '+00:00',
};
// public static initOneClickDeployment() { // public static initOneClickDeployment() {
// if (process.env.NC_ONE_CLICK) { // if (process.env.NC_ONE_CLICK) {
// const url = NcConfigFactory.extractXcUrlFromJdbc(process.env.DATABASE_URL); // const url = NcConfigFactory.extractXcUrlFromJdbc(process.env.DATABASE_URL);

Loading…
Cancel
Save