code cleanup
This commit is contained in:
parent
bd8a79040c
commit
15b6291606
@ -148,8 +148,7 @@ export function modelCustomizationPhase(
|
||||
} else {
|
||||
namingStrategy = new NamingStrategy();
|
||||
}
|
||||
let retVal = setRelationId(generationOptions, dbModel);
|
||||
retVal = applyNamingStrategy(namingStrategy, retVal);
|
||||
let retVal = applyNamingStrategy(namingStrategy, dbModel);
|
||||
retVal = addImportsAndGenerationOptions(retVal, generationOptions);
|
||||
retVal = removeColumnDefaultProperties(retVal, defaultValues);
|
||||
return retVal;
|
||||
@ -216,19 +215,6 @@ function addImportsAndGenerationOptions(
|
||||
return dbModel;
|
||||
}
|
||||
|
||||
function setRelationId(generationOptions: IGenerationOptions, model: Entity[]) {
|
||||
// TODO:
|
||||
// if (generationOptions.relationIds) {
|
||||
// model.forEach(ent => {
|
||||
// ent.columns.forEach(col => {
|
||||
// col.relations.forEach(rel => {
|
||||
// rel.relationIdField = rel.isOwner;
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
return model;
|
||||
}
|
||||
export function modelGenerationPhase(
|
||||
connectionOptions: IConnectionOptions,
|
||||
generationOptions: IGenerationOptions,
|
||||
@ -478,7 +464,6 @@ function applyNamingStrategy(
|
||||
return retval;
|
||||
|
||||
function changeRelationIdNames(model: Entity[]) {
|
||||
// TODO:
|
||||
model.forEach(entity => {
|
||||
entity.relationIds.forEach(relationId => {
|
||||
const oldName = relationId.fieldName;
|
||||
|
@ -315,7 +315,6 @@ export default abstract class AbstractDriver {
|
||||
);
|
||||
isOneToMany = !index;
|
||||
|
||||
// TODO: RelationId
|
||||
ownerEntity.columns = ownerEntity.columns.filter(
|
||||
v =>
|
||||
!relationTmp.ownerColumns.some(u => u === v.tscName) ||
|
||||
@ -367,7 +366,6 @@ export default abstract class AbstractDriver {
|
||||
fieldName: ownerRelation.relatedField,
|
||||
relatedField: ownerRelation.fieldName,
|
||||
relatedTable: relationTmp.ownerTable.tscName,
|
||||
// relationOptions: ownerRelation.relationOptions,
|
||||
relationType: isOneToMany ? "OneToMany" : "OneToOne"
|
||||
};
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
import { ColumnOptions } from "typeorm";
|
||||
import RelationInfo from "./RelationInfo";
|
||||
|
||||
export default class ColumnInfo {
|
||||
public options: ColumnOptions = {};
|
||||
|
||||
public tsName: string = "";
|
||||
|
||||
public tsType:
|
||||
| "number"
|
||||
| "string"
|
||||
| "boolean"
|
||||
| "Date"
|
||||
| "Buffer"
|
||||
| "object"
|
||||
| "string | object"
|
||||
| "string | string[]"
|
||||
| "any"
|
||||
| string;
|
||||
|
||||
public relations: RelationInfo[] = [];
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
import ColumnInfo from "./ColumnInfo";
|
||||
import IndexInfo from "./IndexInfo";
|
||||
|
||||
export default class EntityInfo {
|
||||
public tsEntityName: string;
|
||||
|
||||
public sqlEntityName: string;
|
||||
|
||||
public Columns: ColumnInfo[];
|
||||
|
||||
public Imports: string[];
|
||||
|
||||
public UniqueImports: string[];
|
||||
|
||||
public Indexes: IndexInfo[];
|
||||
|
||||
public Schema?: string;
|
||||
|
||||
public GenerateConstructor: boolean;
|
||||
|
||||
public IsActiveRecord: boolean;
|
||||
|
||||
public Database?: string;
|
||||
|
||||
public relationImports() {
|
||||
const imports: string[] = [];
|
||||
this.Columns.forEach(column => {
|
||||
column.relations.forEach(relation => {
|
||||
if (this.tsEntityName !== relation.relatedTable) {
|
||||
imports.push(relation.relatedTable);
|
||||
}
|
||||
});
|
||||
});
|
||||
this.UniqueImports = imports.filter(
|
||||
(elem, index, self) => index === self.indexOf(elem)
|
||||
);
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
export default interface IndexColumnInfo {
|
||||
name: string;
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
import IndexColumnInfo from "./IndexColumnInfo";
|
||||
|
||||
export default interface IndexInfo {
|
||||
name: string;
|
||||
columns: IndexColumnInfo[];
|
||||
isUnique: boolean;
|
||||
isPrimaryKey: boolean;
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
export default class RelationInfo {
|
||||
public isOwner: boolean;
|
||||
|
||||
public relationType: "OneToOne" | "OneToMany" | "ManyToOne" | "ManyToMany";
|
||||
|
||||
public relatedTable: string;
|
||||
|
||||
public relatedColumn: string;
|
||||
|
||||
public ownerTable: string;
|
||||
|
||||
public ownerColumn: string;
|
||||
|
||||
public actionOnDelete:
|
||||
| "RESTRICT"
|
||||
| "CASCADE"
|
||||
| "SET NULL"
|
||||
| "DEFAULT"
|
||||
| "NO ACTION"
|
||||
| null;
|
||||
|
||||
public actionOnUpdate:
|
||||
| "RESTRICT"
|
||||
| "CASCADE"
|
||||
| "SET NULL"
|
||||
| "DEFAULT"
|
||||
| null;
|
||||
|
||||
public relationIdField: boolean = false;
|
||||
|
||||
public get isOneToMany(): boolean {
|
||||
return this.relationType === "OneToMany";
|
||||
}
|
||||
|
||||
public get isManyToMany(): boolean {
|
||||
return this.relationType === "ManyToMany";
|
||||
}
|
||||
|
||||
public get isOneToOne(): boolean {
|
||||
return this.relationType === "OneToOne";
|
||||
}
|
||||
|
||||
public get isManyToOne(): boolean {
|
||||
return this.relationType === "ManyToOne";
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
export default interface RelationTempInfo {
|
||||
ownerTable: string;
|
||||
ownerColumnsNames: string[];
|
||||
referencedTable: string;
|
||||
referencedColumnsNames: string[];
|
||||
actionOnDelete:
|
||||
| "RESTRICT"
|
||||
| "CASCADE"
|
||||
| "SET NULL"
|
||||
| "DEFAULT"
|
||||
| "NO ACTION"
|
||||
| null;
|
||||
actionOnUpdate: "RESTRICT" | "CASCADE" | "SET NULL" | "DEFAULT" | null;
|
||||
objectId: number | string;
|
||||
}
|
@ -2,10 +2,7 @@ import { expect } from "chai";
|
||||
import * as MSSQL from "mssql";
|
||||
import * as Sinon from "sinon";
|
||||
import MssqlDriver from "../../src/drivers/MssqlDriver";
|
||||
import EntityInfo from "../../src/oldModels/EntityInfo";
|
||||
import ColumnInfo from "../../src/oldModels/ColumnInfo";
|
||||
import IndexInfo from "../../src/oldModels/IndexInfo";
|
||||
import RelationInfo from "../../src/oldModels/RelationInfo";
|
||||
import { Entity } from "../../src/models/Entity";
|
||||
|
||||
interface FakeResponse extends MSSQL.IResult<any> {
|
||||
recordsets: MSSQL.IRecordSet<any>[];
|
||||
@ -26,8 +23,7 @@ class FakeRecordset extends Array<any> implements MSSQL.IRecordSet<any> {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Remove
|
||||
describe.skip("MssqlDriver", function() {
|
||||
describe("MssqlDriver", function() {
|
||||
let driver: MssqlDriver;
|
||||
const sandbox = Sinon.sandbox.create();
|
||||
|
||||
@ -52,14 +48,18 @@ describe.skip("MssqlDriver", function() {
|
||||
}
|
||||
});
|
||||
const result = await driver.GetAllTables("schema", "db");
|
||||
const expectedResult = [] as EntityInfo[];
|
||||
const y = new EntityInfo();
|
||||
y.tsEntityName = "name";
|
||||
y.sqlEntityName = "name";
|
||||
y.Schema = "schema";
|
||||
y.Columns = [] as ColumnInfo[];
|
||||
y.Indexes = [] as IndexInfo[];
|
||||
y.Database = "";
|
||||
const expectedResult = [] as Entity[];
|
||||
const y: Entity = {
|
||||
columns: [],
|
||||
indices: [],
|
||||
relationIds: [],
|
||||
relations: [],
|
||||
sqlName: "name",
|
||||
tscName: "name",
|
||||
schema: "schema",
|
||||
database: "",
|
||||
fileImports: []
|
||||
};
|
||||
expectedResult.push(y);
|
||||
expect(result).to.be.deep.equal(expectedResult);
|
||||
});
|
||||
@ -83,36 +83,38 @@ describe.skip("MssqlDriver", function() {
|
||||
}
|
||||
});
|
||||
|
||||
const entities = [] as EntityInfo[];
|
||||
const y = new EntityInfo();
|
||||
y.tsEntityName = "name";
|
||||
y.Columns = [] as ColumnInfo[];
|
||||
y.Indexes = [] as IndexInfo[];
|
||||
y.Database = "";
|
||||
const entities = [] as Entity[];
|
||||
const y: Entity = {
|
||||
columns: [],
|
||||
indices: [],
|
||||
relationIds: [],
|
||||
relations: [],
|
||||
sqlName: "name",
|
||||
tscName: "name",
|
||||
schema: "schema",
|
||||
database: "",
|
||||
fileImports: []
|
||||
};
|
||||
entities.push(y);
|
||||
const expected: EntityInfo[] = JSON.parse(JSON.stringify(entities));
|
||||
expected[0].Columns.push({
|
||||
const expected: Entity[] = JSON.parse(JSON.stringify(entities));
|
||||
expected[0].columns.push({
|
||||
options: {
|
||||
default: `() => "'a'"`,
|
||||
nullable: true,
|
||||
generated: true,
|
||||
name: "name",
|
||||
unique: false,
|
||||
type: "int"
|
||||
name: "name"
|
||||
},
|
||||
tsName: "name",
|
||||
tsType: "number",
|
||||
relations: [] as RelationInfo[]
|
||||
type: "int",
|
||||
generated: true,
|
||||
default: `() => "'a'"`,
|
||||
tscName: "name",
|
||||
tscType: "number"
|
||||
});
|
||||
|
||||
throw new Error();
|
||||
// TODO: Remove
|
||||
// const result = await driver.GetCoulmnsFromEntity(
|
||||
// entities,
|
||||
// "schema",
|
||||
// "db"
|
||||
// );
|
||||
// expect(result).to.be.deep.equal(expected);
|
||||
const result = await driver.GetCoulmnsFromEntity(
|
||||
entities,
|
||||
"schema",
|
||||
"db"
|
||||
);
|
||||
expect(result).to.be.deep.equal(expected);
|
||||
});
|
||||
it("should find primary indexes");
|
||||
it("should get indexes info");
|
||||
|
@ -10,14 +10,14 @@ import {
|
||||
JoinColumn,
|
||||
JoinTable
|
||||
} from "typeorm";
|
||||
import { users } from "./users";
|
||||
import { quests } from "./quests";
|
||||
import { Users } from "./Users";
|
||||
import { Quests } from "./Quests";
|
||||
|
||||
@Entity("feedextrainfo")
|
||||
@Index("feedExtraInfo_FeedOwnerId_idx", ["feedOwnerId"], { unique: true })
|
||||
@Index("feedExtraInfo_ReaderId_idx", ["readerId"], { unique: true })
|
||||
@Index("feedExtraInfo_QuestId_idx", ["questId"], { unique: true })
|
||||
export class feedextrainfo {
|
||||
export class Feedextrainfo {
|
||||
@PrimaryColumn({ name: "FeedOwnerId" })
|
||||
feedOwnerId: number;
|
||||
|
||||
@ -27,17 +27,17 @@ export class feedextrainfo {
|
||||
@PrimaryColumn({ name: "ReaderId" })
|
||||
readerId: number;
|
||||
|
||||
@OneToOne(type => users, FeedOwnerId => FeedOwnerId.feedextrainfo)
|
||||
@OneToOne(type => Users, FeedOwnerId => FeedOwnerId.feedextrainfo)
|
||||
@JoinColumn({ name: "FeedOwnerId" })
|
||||
feedOwner: users;
|
||||
feedOwner: Users;
|
||||
|
||||
@OneToOne(type => quests, QuestId => QuestId.feedextrainfo)
|
||||
@OneToOne(type => Quests, QuestId => QuestId.feedextrainfo)
|
||||
@JoinColumn({ name: "QuestId" })
|
||||
quest: quests;
|
||||
quest: Quests;
|
||||
|
||||
@OneToOne(type => users, ReaderId => ReaderId.feedextrainfo2)
|
||||
@OneToOne(type => Users, ReaderId => ReaderId.feedextrainfo2)
|
||||
@JoinColumn({ name: "ReaderId" })
|
||||
reader: users;
|
||||
reader: Users;
|
||||
|
||||
@Column("int", {
|
||||
name: "MostUpdatedFeedEntryIdUserRead"
|
@ -10,16 +10,16 @@ import {
|
||||
JoinColumn,
|
||||
JoinTable
|
||||
} from "typeorm";
|
||||
import { feedextrainfo } from "./feedextrainfo";
|
||||
import { Feedextrainfo } from "./Feedextrainfo";
|
||||
|
||||
@Entity("quests")
|
||||
export class quests {
|
||||
export class Quests {
|
||||
@Column("int", {
|
||||
primary: true,
|
||||
name: "QuestId"
|
||||
})
|
||||
questId: number;
|
||||
|
||||
@OneToOne(type => feedextrainfo, feedextrainfo => feedextrainfo.quest)
|
||||
feedextrainfo: feedextrainfo;
|
||||
@OneToOne(type => Feedextrainfo, feedextrainfo => feedextrainfo.quest)
|
||||
feedextrainfo: Feedextrainfo;
|
||||
}
|
@ -10,19 +10,19 @@ import {
|
||||
JoinColumn,
|
||||
JoinTable
|
||||
} from "typeorm";
|
||||
import { feedextrainfo } from "./feedextrainfo";
|
||||
import { Feedextrainfo } from "./Feedextrainfo";
|
||||
|
||||
@Entity("users")
|
||||
export class users {
|
||||
export class Users {
|
||||
@Column("int", {
|
||||
primary: true,
|
||||
name: "UserId"
|
||||
})
|
||||
userId: number;
|
||||
|
||||
@OneToOne(type => feedextrainfo, feedextrainfo => feedextrainfo.feedOwner)
|
||||
feedextrainfo: feedextrainfo;
|
||||
@OneToOne(type => Feedextrainfo, feedextrainfo => feedextrainfo.feedOwner)
|
||||
feedextrainfo: Feedextrainfo;
|
||||
|
||||
@OneToOne(type => feedextrainfo, feedextrainfo2 => feedextrainfo2.reader)
|
||||
feedextrainfo2: feedextrainfo;
|
||||
@OneToOne(type => Feedextrainfo, feedextrainfo2 => feedextrainfo2.reader)
|
||||
feedextrainfo2: Feedextrainfo;
|
||||
}
|
@ -15,8 +15,8 @@ export function getGenerationOptions(resultsPath: string): IGenerationOptions {
|
||||
return {
|
||||
resultsPath,
|
||||
noConfigs: false,
|
||||
convertCaseEntity: "none", // TODO: Change to lib defaults
|
||||
convertCaseFile: "none",
|
||||
convertCaseEntity: "pascal",
|
||||
convertCaseFile: "pascal",
|
||||
convertCaseProperty: "camel",
|
||||
propertyVisibility: "none",
|
||||
lazy: false,
|
||||
|
Loading…
Reference in New Issue
Block a user