Merge pull request #132 from Jared-Dev/master
Add flag to models that use the ActiveRecord syntax.
This commit is contained in:
commit
cd6e38d729
@ -56,6 +56,8 @@ Options:
|
||||
--cp, --case-property Convert property names to specified case
|
||||
[choices: "pascal", "camel", "none"] [default: "none"]
|
||||
--lazy Generate lazy relations [boolean] [default: false]
|
||||
-a, --active-record Generate models that use the ActiveRecord syntax
|
||||
[boolean] [default: false]
|
||||
--namingStrategy Use custom naming strategy
|
||||
--relationIds Generate RelationId fields [boolean] [default: false]
|
||||
--generateConstructor Generate constructor allowing partial initialization
|
||||
|
@ -88,6 +88,7 @@ export class Engine {
|
||||
});
|
||||
});
|
||||
element.GenerateConstructor = this.Options.constructor;
|
||||
element.IsActiveRecord = this.Options.activeRecord;
|
||||
element.Imports.filter((elem, index, self) => {
|
||||
return index === self.indexOf(elem);
|
||||
});
|
||||
@ -274,6 +275,7 @@ export interface IEngineOptions {
|
||||
convertCaseProperty: "pascal" | "camel" | "none";
|
||||
propertyVisibility: "public" | "protected" | "private" | "none";
|
||||
lazy: boolean;
|
||||
activeRecord: boolean;
|
||||
constructor: boolean;
|
||||
namingStrategy: AbstractNamingStrategy;
|
||||
relationIds: boolean;
|
||||
|
@ -1,11 +1,11 @@
|
||||
import {Index,Entity, PrimaryColumn, PrimaryGeneratedColumn, Column, OneToOne, OneToMany, ManyToOne, ManyToMany, JoinColumn, JoinTable, RelationId} from "typeorm";
|
||||
import {BaseEntity,Column,Entity,Index,JoinColumn,JoinTable,ManyToMany,ManyToOne,OneToMany,OneToOne,PrimaryColumn,PrimaryGeneratedColumn,RelationId} from "typeorm";
|
||||
{{relationImports}}{{#each UniqueImports}}import {{curly true}}{{toEntityName this}}{{curly false}} from "./{{toFileName this}}";
|
||||
{{/each}}
|
||||
|
||||
|
||||
@Entity("{{EntityName}}"{{#Schema}},{schema:"{{.}}"}{{/Schema}})
|
||||
{{#Indexes}}{{^isPrimaryKey}}@Index("{{name}}",[{{#columns}}"{{toPropertyName name}}",{{/columns}}]{{#isUnique}},{unique:true}{{/isUnique}})
|
||||
{{/isPrimaryKey}}{{/Indexes}}export class {{toEntityName EntityName}} {
|
||||
{{/isPrimaryKey}}{{/Indexes}}export class {{toEntityName EntityName}}{{#IsActiveRecord}} extends BaseEntity{{/IsActiveRecord}} {
|
||||
{{#Columns}}
|
||||
|
||||
{{^relations}}{{#isGenerated}} @PrimaryGeneratedColumn({
|
||||
|
@ -92,6 +92,12 @@ const argv = Yargs.usage(
|
||||
default: false,
|
||||
describe: "Generate lazy relations"
|
||||
})
|
||||
.option("a", {
|
||||
alias: "active-record",
|
||||
boolean: true,
|
||||
default: false,
|
||||
describe: "Use ActiveRecord syntax for generated models"
|
||||
})
|
||||
.option("namingStrategy", {
|
||||
describe: "Use custom naming strategy"
|
||||
})
|
||||
@ -164,6 +170,7 @@ const engine = new Engine(driver, {
|
||||
databaseType: argv.e,
|
||||
host: argv.h,
|
||||
lazy: argv.lazy,
|
||||
activeRecord: argv.a,
|
||||
namingStrategy,
|
||||
noConfigs: argv.noConfig,
|
||||
password: argv.x ? argv.x.toString() : null,
|
||||
|
@ -8,6 +8,7 @@ export class EntityInfo {
|
||||
public Indexes: IndexInfo[];
|
||||
public Schema: string;
|
||||
public GenerateConstructor: boolean;
|
||||
public IsActiveRecord: boolean;
|
||||
|
||||
public relationImports() {
|
||||
const imports: string[] = [];
|
||||
|
@ -71,7 +71,8 @@ export async function createMSSQLModels(filesOrgPath: string, resultsPath: strin
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
conn = await createConnection(connOpt)
|
||||
@ -143,7 +144,8 @@ export async function createPostgresModels(filesOrgPath: string, resultsPath: st
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
conn = await createConnection(connOpt)
|
||||
@ -207,7 +209,8 @@ export async function createSQLiteModels(filesOrgPath: string, resultsPath: stri
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
conn = await createConnection(connOpt)
|
||||
@ -269,7 +272,8 @@ export async function createMysqlModels(filesOrgPath: string, resultsPath: strin
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
return engine;
|
||||
@ -323,7 +327,8 @@ export async function createMariaDBModels(filesOrgPath: string, resultsPath: str
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
|
||||
@ -380,7 +385,8 @@ export async function createOracleDBModels(filesOrgPath: string, resultsPath: st
|
||||
lazy: false,
|
||||
constructor: false,
|
||||
namingStrategy,
|
||||
relationIds: false
|
||||
relationIds: false,
|
||||
activeRecord: false
|
||||
});
|
||||
|
||||
return engine;
|
||||
|
Loading…
Reference in New Issue
Block a user