From da84c1647582ee316a6cc1cb7a8cb2cf5831037b Mon Sep 17 00:00:00 2001 From: Kononnable Date: Sun, 21 Oct 2018 22:00:48 +0200 Subject: [PATCH] added column type to generated @PrimaryGeneratedColumn decorator --- CHANGELOG.md | 3 +++ src/entity.mst | 3 ++- test/utils/EntityFileToJson.ts | 6 ++++-- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c22175a..fab4d76 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/src/entity.mst b/src/entity.mst index 83e4971..63925ac 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -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}} diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index 3b91d7c..89c6d84 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -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] }