added column type to generated @PrimaryGeneratedColumn decorator

This commit is contained in:
Kononnable 2018-10-21 22:00:48 +02:00
parent c20283bbf9
commit da84c16475
3 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,8 @@
# Changelog
## 0.2.23
* added column type to generated `@PrimaryGeneratedColumn` decorator
## 0.2.22
* fixed naming stategy for guid ended column names
* fixed column names case convertion in index declarations

View File

@ -8,7 +8,8 @@ import {Index,Entity, PrimaryColumn, PrimaryGeneratedColumn, Column, OneToOne, O
{{/isPrimaryKey}}{{/Indexes}}export class {{toEntityName EntityName}} {
{{#Columns}}
{{^relations}}{{#is_generated}} @PrimaryGeneratedColumn({ {{/is_generated}}{{^is_generated}} @Column("{{sql_type}}",{ {{#is_nullable}}
{{^relations}}{{#is_generated}} @PrimaryGeneratedColumn({
type:"{{sql_type}}", {{/is_generated}}{{^is_generated}} @Column("{{sql_type}}",{ {{#is_nullable}}
nullable:true,{{/is_nullable}}{{^is_nullable}}
nullable:false,{{/is_nullable}}{{#isPrimary}}
primary:{{isPrimary}},{{/isPrimary}}{{/is_generated}}{{#is_unique}}

View File

@ -16,8 +16,9 @@ export class EntityFileToJson {
}
getColumnOptionsAndType(trimmedLine: string, col: EntityColumn) {
let decoratorParameters = trimmedLine.slice(trimmedLine.indexOf('(') + 1, trimmedLine.lastIndexOf(')'))
let primaryGeneratedColumn = trimmedLine.substring(0, trimmedLine.indexOf('('))=='@PrimaryGeneratedColumn'
if (decoratorParameters.length > 0) {
if (decoratorParameters.search(',') > 0) {
if (decoratorParameters.search(',') > 0 && !primaryGeneratedColumn) {
col.columnTypes = decoratorParameters.substring(0, decoratorParameters.indexOf(',')).trim().split('|').map(function (x) {
return x;
});
@ -33,7 +34,8 @@ export class EntityFileToJson {
return x;
});
} else {
let badJSON = decoratorParameters.substring(decoratorParameters.indexOf(',') + 1).trim()
let badJSON = !primaryGeneratedColumn ? decoratorParameters.substring(decoratorParameters.indexOf(',') + 1) : decoratorParameters
badJSON = badJSON.trim()
if (badJSON.lastIndexOf(',') == badJSON.length - 3) {
badJSON = badJSON.slice(0, badJSON.length - 3) + badJSON[badJSON.length - 2] + badJSON[badJSON.length - 1]
}