From 9ca015e377c4ff9032ea821a9bd1e20d98607dce Mon Sep 17 00:00:00 2001 From: Ng Tze Yang Date: Thu, 27 Jun 2019 09:27:08 +0800 Subject: [PATCH] feat: support richer derivation of column & entity name ; --- src/AbstractNamingStrategy.ts | 5 +++-- src/Engine.ts | 4 ++-- src/NamingStrategy.ts | 5 +++-- 3 files changed, 8 insertions(+), 6 deletions(-) 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; } }