From d46738e9323bc831b0362ed72f4c27b3a4e99fa2 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 25 Mar 2018 01:13:16 +0100 Subject: [PATCH] code cleaning --- src/drivers/AbstractDriver.ts | 23 ++++++++++++++++++++++- src/drivers/MssqlDriver.ts | 21 --------------------- src/drivers/MysqlDriver.ts | 21 --------------------- src/drivers/OracleDriver.ts | 21 --------------------- src/drivers/PostgresDriver.ts | 21 --------------------- src/models/DatabaseModel.ts | 19 ------------------- 6 files changed, 22 insertions(+), 104 deletions(-) diff --git a/src/drivers/AbstractDriver.ts b/src/drivers/AbstractDriver.ts index c5494f4..b69f656 100644 --- a/src/drivers/AbstractDriver.ts +++ b/src/drivers/AbstractDriver.ts @@ -1,5 +1,6 @@ import { EntityInfo } from "./../models/EntityInfo"; import { DatabaseModel } from "./../models/DatabaseModel"; +import * as TomgUtils from "./../Utils"; /** * AbstractDriver */ @@ -48,7 +49,27 @@ export abstract class AbstractDriver { entities: EntityInfo[], schema: string ): Promise; - abstract async FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel); + + FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { + dbModel.entities.forEach(entity => { + let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); + if (!primaryIndex) { + TomgUtils.LogFatalError( + `Table ${entity.EntityName} has no PK.`, + false + ); + return; + } + entity.Columns.forEach(col => { + if ( + primaryIndex!.columns.some( + cIndex => cIndex.name == col.name + ) + ) + col.isPrimary = true; + }); + }); + } abstract async DisconnectFromServer(); abstract async CreateDB(dbName: string); diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index 9c56fde..6997d17 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -10,27 +10,6 @@ import * as TomgUtils from "./../Utils"; * MssqlDriver */ export class MssqlDriver extends AbstractDriver { - FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { - dbModel.entities.forEach(entity => { - let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); - if (!primaryIndex) { - TomgUtils.LogFatalError( - `Table ${entity.EntityName} has no PK.`, - false - ); - return; - } - entity.Columns.forEach(col => { - if ( - primaryIndex!.columns.some( - cIndex => cIndex.name == col.name - ) - ) - col.isPrimary = true; - }); - }); - } - async GetAllTables(schema: string): Promise { let request = new MSSQL.Request(this.Connection); let response: { diff --git a/src/drivers/MysqlDriver.ts b/src/drivers/MysqlDriver.ts index e631edf..7bf6875 100644 --- a/src/drivers/MysqlDriver.ts +++ b/src/drivers/MysqlDriver.ts @@ -11,27 +11,6 @@ import * as TomgUtils from "./../Utils"; export class MysqlDriver extends AbstractDriver { readonly EngineName: string = "MySQL"; - FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { - dbModel.entities.forEach(entity => { - let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); - if (!primaryIndex) { - TomgUtils.LogFatalError( - `Table ${entity.EntityName} has no PK.`, - false - ); - return; - } - entity.Columns.forEach(col => { - if ( - primaryIndex!.columns.some( - cIndex => cIndex.name == col.name - ) - ) - col.isPrimary = true; - }); - }); - } - async GetAllTables(schema: string): Promise { let response = await this.ExecQuery<{ TABLE_SCHEMA: string; diff --git a/src/drivers/OracleDriver.ts b/src/drivers/OracleDriver.ts index 8a1d3f5..4246a29 100644 --- a/src/drivers/OracleDriver.ts +++ b/src/drivers/OracleDriver.ts @@ -22,27 +22,6 @@ export class OracleDriver extends AbstractDriver { } } - FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { - dbModel.entities.forEach(entity => { - let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); - if (!primaryIndex) { - TomgUtils.LogFatalError( - `Table ${entity.EntityName} has no PK.`, - false - ); - return; - } - entity.Columns.forEach(col => { - if ( - primaryIndex!.columns.some( - cIndex => cIndex.name == col.name - ) - ) - col.isPrimary = true; - }); - }); - } - async GetAllTables(schema: string): Promise { let response: any[][] = (await this.Connection.execute( ` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)` diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index ccef3ad..a785979 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -11,27 +11,6 @@ import * as TomgUtils from "./../Utils"; export class PostgresDriver extends AbstractDriver { private Connection: PG.Client; - FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) { - dbModel.entities.forEach(entity => { - let primaryIndex = entity.Indexes.find(v => v.isPrimaryKey); - if (!primaryIndex) { - TomgUtils.LogFatalError( - `Table ${entity.EntityName} has no PK.`, - false - ); - return; - } - entity.Columns.forEach(col => { - if ( - primaryIndex!.columns.some( - cIndex => cIndex.name == col.name - ) - ) - col.isPrimary = true; - }); - }); - } - async GetAllTables(schema: string): Promise { let response: { table_schema: string; diff --git a/src/models/DatabaseModel.ts b/src/models/DatabaseModel.ts index e3d409e..27c6b7b 100644 --- a/src/models/DatabaseModel.ts +++ b/src/models/DatabaseModel.ts @@ -1,23 +1,4 @@ import { EntityInfo } from "./EntityInfo"; export class DatabaseModel { entities: EntityInfo[]; - config: { - cascadeInsert: boolean; - cascadeUpdate: boolean; - cascadeRemove: boolean; - }; - - //TODO:check if unused - relationImports(): any { - let that = this; - return function(text, render) { - if ("l" != render(text)) - return `import {{curly true}}{{toEntityName ${render( - text - )}}}{{curly false}} from "./{{ ${render( - "toFileName" + text - )}}}`; - else return ""; - }; - } }