diff --git a/src/AbstractNamingStrategy.ts b/src/AbstractNamingStrategy.ts index ee3b9ee..c523ad1 100644 --- a/src/AbstractNamingStrategy.ts +++ b/src/AbstractNamingStrategy.ts @@ -1,4 +1,5 @@ import { EntityInfo } from "./models/EntityInfo"; +import { ColumnInfo } from "./models/ColumnInfo"; import { RelationInfo } from "./models/RelationInfo"; export abstract class AbstractNamingStrategy { @@ -8,7 +9,7 @@ export abstract class AbstractNamingStrategy { dbModel: EntityInfo[] ): string; - public abstract entityName(entityName: string): string; + public abstract entityName(entityName: string, entity?: EntityInfo): string; - public abstract columnName(columnName: string): string; + public abstract columnName(columnName: string, column?: ColumnInfo): string; } diff --git a/src/Engine.ts b/src/Engine.ts index bf4efe6..19be9a6 100644 --- a/src/Engine.ts +++ b/src/Engine.ts @@ -419,7 +419,7 @@ function applyNamingStrategy( function changeColumnNames(model: EntityInfo[]) { model.forEach(entity => { entity.Columns.forEach(column => { - const newName = namingStrategy.columnName(column.tsName); + const newName = namingStrategy.columnName(column.tsName, column); entity.Indexes.forEach(index => { index.columns .filter(column2 => column2.name === column.tsName) @@ -453,7 +453,7 @@ function applyNamingStrategy( } function changeEntityNames(entities: EntityInfo[]) { entities.forEach(entity => { - const newName = namingStrategy.entityName(entity.tsEntityName); + const newName = namingStrategy.entityName(entity.tsEntityName, entity); entities.forEach(entity2 => { entity2.Columns.forEach(column => { column.relations.forEach(relation => { diff --git a/src/NamingStrategy.ts b/src/NamingStrategy.ts index 4e814d6..9b951d0 100644 --- a/src/NamingStrategy.ts +++ b/src/NamingStrategy.ts @@ -1,6 +1,7 @@ import changeCase = require("change-case"); import { AbstractNamingStrategy } from "./AbstractNamingStrategy"; import { EntityInfo } from "./models/EntityInfo"; +import { ColumnInfo } from "./models/ColumnInfo"; import { RelationInfo } from "./models/RelationInfo"; export class NamingStrategy extends AbstractNamingStrategy { @@ -60,11 +61,11 @@ export class NamingStrategy extends AbstractNamingStrategy { return columnName; } - public entityName(entityName: string): string { + public entityName(entityName: string, entity?: EntityInfo): string { return entityName; } - public columnName(columnName: string): string { + public columnName(columnName: string, column?: ColumnInfo): string { return columnName; } }