merge master branch
This commit is contained in:
commit
af210c6e83
@ -146,6 +146,10 @@ function addImportsAndGenerationOptions(
|
||||
element.Imports.filter((elem, index, self) => {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
if (generationOptions.skipSchema) {
|
||||
element.Schema = undefined;
|
||||
element.Database = undefined;
|
||||
}
|
||||
});
|
||||
return dbModel;
|
||||
}
|
||||
|
@ -23,4 +23,6 @@ export default class IGenerationOptions {
|
||||
public relationIds: boolean = false;
|
||||
|
||||
public strictMode: false | "?" | "!" = false;
|
||||
|
||||
public skipSchema: boolean = false;
|
||||
}
|
||||
|
@ -216,6 +216,33 @@ export default abstract class AbstractDriver {
|
||||
entities: EntityInfo[]
|
||||
) {
|
||||
relationsTemp.forEach(relationTmp => {
|
||||
if (relationTmp.ownerColumnsNames.length > 1) {
|
||||
const relatedTable = entities.find(
|
||||
entity => entity.tsEntityName === relationTmp.ownerTable
|
||||
)!;
|
||||
if (
|
||||
relatedTable.Columns.length !==
|
||||
relationTmp.ownerColumnsNames.length * 2
|
||||
) {
|
||||
TomgUtils.LogError(
|
||||
`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} wasn't generated correctly - complex relationships aren't supported yet.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const secondRelation = relationsTemp.find(
|
||||
relation =>
|
||||
relation.ownerTable === relatedTable.tsEntityName &&
|
||||
relation.referencedTable !== relationTmp.referencedTable
|
||||
)!;
|
||||
if (!secondRelation) {
|
||||
TomgUtils.LogError(
|
||||
`Relation between tables ${relationTmp.ownerTable} and ${relationTmp.referencedTable} wasn't generated correctly - complex relationships aren't supported yet.`
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
const ownerEntity = entities.find(
|
||||
entitity => entitity.tsEntityName === relationTmp.ownerTable
|
||||
);
|
||||
|
@ -3,7 +3,7 @@ import {BaseEntity,Column,Entity,Index,JoinColumn,JoinTable,ManyToMany,ManyToOne
|
||||
{{/each}}
|
||||
|
||||
|
||||
@Entity("{{sqlEntityName}}"{{#Schema}},{schema:"{{.}}"{{#if ../Database}}, database:"{{../Database}}"{{/if}} } {{/Schema}})
|
||||
@Entity("{{sqlEntityName}}"{{#Schema}} ,{schema:"{{.}}"{{#if ../Database}}, database:"{{../Database}}"{{/if}} } {{/Schema}})
|
||||
{{#Indexes}}{{^isPrimaryKey}}@Index("{{name}}",[{{#columns}}"{{toPropertyName name}}",{{/columns}}]{{#isUnique}},{unique:true}{{/isUnique}})
|
||||
{{/isPrimaryKey}}{{/Indexes}}export class {{toEntityName tsEntityName}}{{#IsActiveRecord}} extends BaseEntity{{/IsActiveRecord}} {
|
||||
{{#Columns}}
|
||||
|
11
src/index.ts
11
src/index.ts
@ -153,6 +153,11 @@ function GetUtilParametersByArgs() {
|
||||
default: false,
|
||||
describe: "Generate RelationId fields"
|
||||
})
|
||||
.option("skipSchema", {
|
||||
boolean: true,
|
||||
default: false,
|
||||
describe: "Omits schema identifier in generated entities"
|
||||
})
|
||||
.option("generateConstructor", {
|
||||
boolean: true,
|
||||
default: false,
|
||||
@ -199,6 +204,7 @@ function GetUtilParametersByArgs() {
|
||||
generationOptions.noConfigs = argv.noConfig;
|
||||
generationOptions.propertyVisibility = argv.pv;
|
||||
generationOptions.relationIds = argv.relationIds;
|
||||
generationOptions.skipSchema = argv.skipSchema;
|
||||
generationOptions.resultsPath = argv.o ? argv.o.toString() : null;
|
||||
generationOptions.strictMode =
|
||||
argv.strictMode === "none" ? false : argv.strictMode;
|
||||
@ -370,6 +376,10 @@ async function GetUtilParametersByInquirer() {
|
||||
name: "Generate RelationId fields",
|
||||
value: "relationId"
|
||||
},
|
||||
{
|
||||
name: "Omits schema identifier in generated entities",
|
||||
value: "skipSchema"
|
||||
},
|
||||
{
|
||||
name:
|
||||
"Generate constructor allowing partial initialization",
|
||||
@ -415,6 +425,7 @@ async function GetUtilParametersByInquirer() {
|
||||
"activeRecord"
|
||||
);
|
||||
generationOptions.relationIds = customizations.includes("relationId");
|
||||
generationOptions.skipSchema = customizations.includes("skipSchema");
|
||||
generationOptions.generateConstructor = customizations.includes(
|
||||
"constructor"
|
||||
);
|
||||
|
@ -14,13 +14,13 @@ export default class EntityInfo {
|
||||
|
||||
public Indexes: IndexInfo[];
|
||||
|
||||
public Schema: string;
|
||||
public Schema?: string;
|
||||
|
||||
public GenerateConstructor: boolean;
|
||||
|
||||
public IsActiveRecord: boolean;
|
||||
|
||||
public Database: string;
|
||||
public Database?: string;
|
||||
|
||||
public relationImports() {
|
||||
const imports: string[] = [];
|
||||
|
@ -23,6 +23,7 @@ export function getGenerationOptions(resultsPath: string): IGenerationOptions {
|
||||
generateConstructor: false,
|
||||
customNamingStrategyPath: "",
|
||||
relationIds: false,
|
||||
skipSchema: false,
|
||||
activeRecord: false
|
||||
};
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user