Added support for detached entities, i.e. entities which are not attached to a schema and database.
This commit is contained in:
parent
b70aba10c8
commit
031d74b39c
@ -144,6 +144,7 @@ function addImportsAndGenerationOptions(
|
||||
});
|
||||
element.GenerateConstructor = generationOptions.generateConstructor;
|
||||
element.IsActiveRecord = generationOptions.activeRecord;
|
||||
element.detached = generationOptions.detached;
|
||||
element.Imports.filter((elem, index, self) => {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
|
@ -11,4 +11,5 @@ export class IGenerationOptions {
|
||||
public generateConstructor: boolean = false;
|
||||
public customNamingStrategyPath: string = "";
|
||||
public relationIds: boolean = false;
|
||||
public detached: boolean = false;
|
||||
}
|
||||
|
@ -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}}"{{#unless detached}}{{#Schema}} ,{schema:"{{.}}"{{#if ../Database}}, database:"{{../Database}}"{{/if}} } {{/Schema}}{{/unless}})
|
||||
{{#Indexes}}{{^isPrimaryKey}}@Index("{{name}}",[{{#columns}}"{{toPropertyName name}}",{{/columns}}]{{#isUnique}},{unique:true}{{/isUnique}})
|
||||
{{/isPrimaryKey}}{{/Indexes}}export class {{toEntityName tsEntityName}}{{#IsActiveRecord}} extends BaseEntity{{/IsActiveRecord}} {
|
||||
{{#Columns}}
|
||||
|
13
src/index.ts
13
src/index.ts
@ -157,6 +157,12 @@ function GetUtilParametersByArgs() {
|
||||
default: false,
|
||||
describe: "Generate RelationId fields"
|
||||
})
|
||||
.option("detached", {
|
||||
boolean: true,
|
||||
default: false,
|
||||
describe:
|
||||
"If set, omits database and schema identifier in generated entities"
|
||||
})
|
||||
.option("generateConstructor", {
|
||||
boolean: true,
|
||||
default: false,
|
||||
@ -196,6 +202,7 @@ function GetUtilParametersByArgs() {
|
||||
(generationOptions.noConfigs = argv.noConfig),
|
||||
(generationOptions.propertyVisibility = argv.pv),
|
||||
(generationOptions.relationIds = argv.relationIds),
|
||||
(generationOptions.detached = argv.detached),
|
||||
(generationOptions.resultsPath = argv.o ? argv.o.toString() : null);
|
||||
|
||||
return { driver, connectionOptions, generationOptions };
|
||||
@ -339,6 +346,11 @@ async function GetUtilParametersByInquirer() {
|
||||
name: "Generate RelationId fields",
|
||||
value: "relationId"
|
||||
},
|
||||
{
|
||||
name:
|
||||
"Omit schema qualifier, allowing you to switch it at runtime",
|
||||
value: "detached"
|
||||
},
|
||||
{
|
||||
name:
|
||||
"Generate constructor allowing partial initialization",
|
||||
@ -360,6 +372,7 @@ async function GetUtilParametersByInquirer() {
|
||||
"activeRecord"
|
||||
);
|
||||
generationOptions.relationIds = customizations.includes("relationId");
|
||||
generationOptions.detached = customizations.includes("detached");
|
||||
generationOptions.generateConstructor = customizations.includes(
|
||||
"constructor"
|
||||
);
|
||||
|
@ -10,6 +10,7 @@ export class EntityInfo {
|
||||
public Indexes: IndexInfo[];
|
||||
public Schema: string;
|
||||
public GenerateConstructor: boolean;
|
||||
public detached: boolean;
|
||||
public IsActiveRecord: boolean;
|
||||
public Database: string;
|
||||
|
||||
|
@ -24,6 +24,7 @@ export function getGenerationOptions(resultsPath: string): IGenerationOptions {
|
||||
generateConstructor: false,
|
||||
customNamingStrategyPath: "",
|
||||
relationIds: false,
|
||||
detached: false,
|
||||
activeRecord: false
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user