From 52884da881f6a65cfcfc47fdee6a106e280d2905 Mon Sep 17 00:00:00 2001 From: Kononnable Date: Mon, 5 Jun 2017 16:01:35 +0200 Subject: [PATCH] added column types tests --- src/drivers/MssqlDriver.ts | 12 +++- src/entity.mst | 6 +- src/models/ColumnInfo.ts | 4 +- .../entity/EverythingEntity.ts | 72 +++++++++++++++++++ test/utils/EntityFileToJson.ts | 3 + 5 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index 88f7e19..d28451a 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -75,12 +75,20 @@ export class MssqlDriver extends AbstractDriver { colInfo.ts_type = "number" colInfo.sql_type = "float" break; - case "date": + case "bigint": colInfo.ts_type = "number" + colInfo.sql_type = "bigint" + break; + case "date": + colInfo.ts_type = "Date" colInfo.sql_type = "date" break; + case "time": + colInfo.ts_type = "Date" + colInfo.sql_type = "time" + break; case "datetime": - colInfo.ts_type = "number"; + colInfo.ts_type = "Date"; colInfo.sql_type = "datetime" break; case "char": diff --git a/src/entity.mst b/src/entity.mst index f8c7173..eef4c55 100644 --- a/src/entity.mst +++ b/src/entity.mst @@ -12,9 +12,9 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi nullable:true,{{/is_nullable}}{{^is_nullable}} nullable:false,{{/is_nullable}}{{#char_max_lenght}} length:{{.}},{{/char_max_lenght}}{{#default}} - default:"{{default}}",{{/default}}{{#numericPrecision}} - precision:{{numericPrecision}},{{/numericPrecision}}{{#numericScale}} - scale:{{numericScale}},{{/numericScale}}{{#isPrimary}} + default:"{{.}}",{{/default}}{{#numericPrecision}} + precision:{{.}},{{/numericPrecision}}{{#numericScale}} + scale:{{.}},{{/numericScale}}{{#isPrimary}} primary:{{isPrimary}},{{/isPrimary}} }) {{name}}:{{ts_type}}; diff --git a/src/models/ColumnInfo.ts b/src/models/ColumnInfo.ts index a8030e2..1ebdd5b 100644 --- a/src/models/ColumnInfo.ts +++ b/src/models/ColumnInfo.ts @@ -6,9 +6,9 @@ export class ColumnInfo { name: string=''; default: string|null=null; is_nullable: boolean=false; - ts_type: 'number' | 'string' | 'boolean'; + ts_type: 'number' | 'string' | 'boolean' | 'Date'; sql_type: "string" | "text" | "number" | "integer" | "int" | "smallint" | "bigint" | - "float" | "double" | "decimal" | "date" | "time" | "datetime" | "boolean" | "json"; + "float" | "double" | "decimal" | "date" | "time" | "datetime" | "boolean" | "json" ; char_max_lenght: number|null=null; isPrimary:boolean=false; is_generated:boolean=false; diff --git a/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts b/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts new file mode 100644 index 0000000..7a5224d --- /dev/null +++ b/test/integration/examples/sample11-all-types-entity/entity/EverythingEntity.ts @@ -0,0 +1,72 @@ +import { PrimaryGeneratedColumn, Column, Entity, OneToOne, JoinColumn, Index } from "typeorm"; + +@Entity("EverythingEntity") +export class EverythingEntity { + + @PrimaryGeneratedColumn() + id: number; + + @Column() + name: string; + + @Column("text") + text: string; + + @Column({ length: 32 }) + shortTextColumn: string; + + @Column() + numberColumn: number; + + @Column("integer") + integerColumn: number; + + @Column("int") + intColumn: number; + + @Column("smallint") + smallintColumn: number; + + @Column("bigint") + bigintColumn: number; + + @Column("float") + floatColumn: number; + + @Column("double") + doubleColumn: number; + + @Column("decimal") + decimalColumn: number; + + @Column() + date: Date; + + @Column("date") + dateColumn: Date; + + @Column("time") + timeColumn: Date; + + @Column("boolean") + isBooleanColumn: boolean; + + @Column("boolean") + isSecondBooleanColumn: boolean; + + @Column("json") + jsonColumn: any; + + // @Column() + // alsoJson: any; + + // @Column("simple_array") + // simpleArrayColumn: string[]; + + // @CreateDateColumn() + // createdDate: Date; + + // @UpdateDateColumn() + // updatedDate: Date; + +} \ No newline at end of file diff --git a/test/utils/EntityFileToJson.ts b/test/utils/EntityFileToJson.ts index b1c5e09..53daa96 100644 --- a/test/utils/EntityFileToJson.ts +++ b/test/utils/EntityFileToJson.ts @@ -172,6 +172,9 @@ export class EntityFileToJson { retVal.columns[retVal.columns.length - 1].columnName = trimmedLine.split(':')[0].trim(); //TODO:Should check if null only column is nullable? retVal.columns[retVal.columns.length - 1].columnTypes = trimmedLine.split(':')[1].split(';')[0].trim().split('|').map(function (x) { + if (x=='any') { + x='string' //for json columns + } // if (!x.endsWith('[]')) { // x = x + '[]'// can't distinguish OneTwoMany from OneToOne without indexes // }