diff --git a/src/common/interfaces/antares.ts b/src/common/interfaces/antares.ts index 9e75a34d..3532c0c6 100644 --- a/src/common/interfaces/antares.ts +++ b/src/common/interfaces/antares.ts @@ -58,6 +58,15 @@ export interface ConnectionParams { sshPassphrase?: string; } +export interface TypeInformations { + name: string; + length: boolean; + scale: boolean; + collation: boolean; + unsigned: boolean; + zerofill: boolean; +} + // Tables export interface TableField { name: string; diff --git a/src/main/libs/clients/MySQLClient.ts b/src/main/libs/clients/MySQLClient.ts index 6f49ccca..0357180b 100644 --- a/src/main/libs/clients/MySQLClient.ts +++ b/src/main/libs/clients/MySQLClient.ts @@ -102,7 +102,7 @@ export class MySQLClient extends AntaresCore { return { name, length }; } - _getTypeInfo (type: string) { + getTypeInfo (type: string): antares.TypeInformations { return dataTypes .reduce((acc, group) => [...acc, ...group.types], []) .filter((_type) => _type.name === type.toUpperCase())[0]; @@ -745,7 +745,7 @@ export class MySQLClient extends AntaresCore { // ADD FIELDS fields.forEach(field => { - const typeInfo = this._getTypeInfo(field.type); + const typeInfo = this.getTypeInfo(field.type); const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; newColumns.push(`\`${field.name}\` @@ -808,7 +808,7 @@ export class MySQLClient extends AntaresCore { // ADD FIELDS additions.forEach(addition => { - const typeInfo = this._getTypeInfo(addition.type); + const typeInfo = this.getTypeInfo(addition.type); const length = typeInfo.length ? addition.enumValues || addition.numLength || addition.charLength || addition.datePrecision : false; alterColumns.push(`ADD COLUMN \`${addition.name}\` @@ -846,7 +846,7 @@ export class MySQLClient extends AntaresCore { // CHANGE FIELDS changes.forEach(change => { - const typeInfo = this._getTypeInfo(change.type); + const typeInfo = this.getTypeInfo(change.type); const length = typeInfo.length ? change.enumValues || change.numLength || change.charLength || change.datePrecision : false; alterColumns.push(`CHANGE COLUMN \`${change.orgName}\` \`${change.name}\` diff --git a/src/main/libs/clients/PostgreSQLClient.ts b/src/main/libs/clients/PostgreSQLClient.ts index d42afc57..5727e26a 100644 --- a/src/main/libs/clients/PostgreSQLClient.ts +++ b/src/main/libs/clients/PostgreSQLClient.ts @@ -71,7 +71,7 @@ export class PostgreSQLClient extends AntaresCore { } } - _getTypeInfo (type: string) { + getTypeInfo (type: string): antares.TypeInformations { return dataTypes .reduce((acc, group) => [...acc, ...group.types], []) .filter(_type => _type.name === type.toUpperCase())[0]; @@ -604,7 +604,7 @@ export class PostgreSQLClient extends AntaresCore { // ADD FIELDS fields.forEach(field => { - const typeInfo = this._getTypeInfo(field.type); + const typeInfo = this.getTypeInfo(field.type); const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; newColumns.push(`"${field.name}" @@ -663,7 +663,7 @@ export class PostgreSQLClient extends AntaresCore { // ADD FIELDS additions.forEach(addition => { - const typeInfo = this._getTypeInfo(addition.type); + const typeInfo = this.getTypeInfo(addition.type); const length = typeInfo.length ? addition.numLength || addition.charLength || addition.datePrecision : false; alterColumns.push(`ADD COLUMN "${addition.name}" @@ -695,7 +695,7 @@ export class PostgreSQLClient extends AntaresCore { // CHANGE FIELDS changes.forEach(change => { - const typeInfo = this._getTypeInfo(change.type); + const typeInfo = this.getTypeInfo(change.type); const length = typeInfo.length ? change.numLength || change.charLength || change.datePrecision : false; let localType; diff --git a/src/main/libs/clients/SQLiteClient.ts b/src/main/libs/clients/SQLiteClient.ts index 56413aed..c908bfad 100644 --- a/src/main/libs/clients/SQLiteClient.ts +++ b/src/main/libs/clients/SQLiteClient.ts @@ -17,7 +17,7 @@ export class SQLiteClient extends AntaresCore { this._connectionsToCommit = new Map(); } - _getTypeInfo (type: string) { + getTypeInfo (type: string): antares.TypeInformations { return dataTypes .reduce((acc, group) => [...acc, ...group.types], []) .filter(_type => _type.name === type.toUpperCase())[0]; @@ -298,7 +298,7 @@ export class SQLiteClient extends AntaresCore { // ADD FIELDS fields.forEach(field => { - const typeInfo = this._getTypeInfo(field.type); + const typeInfo = this.getTypeInfo(field.type); const length = typeInfo?.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; newColumns.push(`"${field.name}" diff --git a/src/main/libs/exporters/sql/MysqlExporter.ts b/src/main/libs/exporters/sql/MysqlExporter.ts index 9c97f5f6..713c51cc 100644 --- a/src/main/libs/exporters/sql/MysqlExporter.ts +++ b/src/main/libs/exporters/sql/MysqlExporter.ts @@ -205,7 +205,7 @@ ${footer} const tableFields: string[] = []; for (const field of viewFields) { - const typeInfo = this._client._getTypeInfo(field.type); + const typeInfo = this._client.getTypeInfo(field.type); const length = typeInfo.length ? field.enumValues || field.numLength || field.charLength || field.datePrecision : false; tableFields.push(`\`${field.name}\` ${field.type.toUpperCase()}${length ? `(${length}${field.numScale ? `,${field.numScale}` : ''})` : ''} ${field.unsigned ? 'UNSIGNED' : ''} ${field.zerofill ? 'ZEROFILL' : ''} ${field.nullable ? 'NULL' : 'NOT NULL'} ${field.autoIncrement ? 'AUTO_INCREMENT' : ''} ${field.collation ? `COLLATE ${field.collation}` : ''}`);