feat: support richer derivation of column & entity name ;

This commit is contained in:
Ng Tze Yang 2019-06-27 09:27:08 +08:00
parent b70aba10c8
commit 9ca015e377
3 changed files with 8 additions and 6 deletions

View File

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

View File

@ -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 => {

View File

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