code cleaning

This commit is contained in:
Kononnable 2018-03-25 01:13:16 +01:00
parent 492b068b94
commit d46738e932
6 changed files with 22 additions and 104 deletions

View File

@ -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<EntityInfo[]>;
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);

View File

@ -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<EntityInfo[]> {
let request = new MSSQL.Request(this.Connection);
let response: {

View File

@ -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<EntityInfo[]> {
let response = await this.ExecQuery<{
TABLE_SCHEMA: string;

View File

@ -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<EntityInfo[]> {
let response: any[][] = (await this.Connection.execute(
` SELECT TABLE_NAME FROM all_tables WHERE owner = (select user from dual)`

View File

@ -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<EntityInfo[]> {
let response: {
table_schema: string;

View File

@ -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 "";
};
}
}