Adding type enum for mysql/mariadb; fixes #28
This commit is contained in:
parent
d689121875
commit
984238db02
@ -44,10 +44,10 @@ export class MysqlDriver extends AbstractDriver {
|
||||
let response = await this.ExecQuery<{
|
||||
TABLE_NAME: string, COLUMN_NAME: string, COLUMN_DEFAULT: string,
|
||||
IS_NULLABLE: string, DATA_TYPE: string, CHARACTER_MAXIMUM_LENGTH: number,
|
||||
NUMERIC_PRECISION: number, NUMERIC_SCALE: number, IsIdentity: number
|
||||
NUMERIC_PRECISION: number, NUMERIC_SCALE: number, IsIdentity: number, column_type:string
|
||||
}>(`SELECT TABLE_NAME,COLUMN_NAME,COLUMN_DEFAULT,IS_NULLABLE,
|
||||
DATA_TYPE,CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION,NUMERIC_SCALE,
|
||||
CASE WHEN EXTRA like '%auto_increment%' THEN 1 ELSE 0 END IsIdentity FROM INFORMATION_SCHEMA.COLUMNS
|
||||
CASE WHEN EXTRA like '%auto_increment%' THEN 1 ELSE 0 END IsIdentity, column_type FROM INFORMATION_SCHEMA.COLUMNS
|
||||
where TABLE_SCHEMA like DATABASE()`);
|
||||
entities.forEach((ent) => {
|
||||
response.filter((filterVal) => {
|
||||
@ -196,6 +196,11 @@ export class MysqlDriver extends AbstractDriver {
|
||||
colInfo.ts_type = "Object"
|
||||
colInfo.sql_type = "json"
|
||||
break;
|
||||
case "enum":
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "enum"
|
||||
colInfo.enumOptions = resp.column_type.substring(5, resp.column_type.length - 1).replace(/\'/gi,'"')
|
||||
break;
|
||||
default:
|
||||
TomgUtils.LogFatalError("Unknown column type:" + resp.DATA_TYPE);
|
||||
break;
|
||||
|
@ -208,7 +208,6 @@ export class PostgresDriver extends AbstractDriver {
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "xml"
|
||||
break;
|
||||
|
||||
default:
|
||||
TomgUtils.LogFatalError("Unknown column type:" + resp.data_type);
|
||||
break;
|
||||
|
@ -16,7 +16,8 @@ import {Index,Entity, PrimaryColumn, Column, OneToOne, OneToMany, ManyToOne, Joi
|
||||
default:"{{.}}",{{/default}}{{#numericPrecision}}
|
||||
precision:{{.}},{{/numericPrecision}}{{#numericScale}}
|
||||
scale:{{.}},{{/numericScale}}{{#isPrimary}}
|
||||
primary:{{isPrimary}},{{/isPrimary}}
|
||||
primary:{{isPrimary}},{{/isPrimary}}{{#enumOptions}}
|
||||
enum:[{{.}}],{{/enumOptions}}
|
||||
name:"{{name}}"
|
||||
})
|
||||
{{toPropertyName name}}:{{ts_type}};
|
||||
|
@ -14,6 +14,7 @@ export class ColumnInfo {
|
||||
is_generated: boolean = false;
|
||||
numericPrecision: number | null = null;
|
||||
numericScale: number | null = null;
|
||||
enumOptions: string | null = null;
|
||||
relations: RelationInfo[];
|
||||
|
||||
|
||||
|
@ -103,6 +103,7 @@ describe('MssqlDriver', function () {
|
||||
numericScale: null,
|
||||
sql_type: 'int',
|
||||
ts_type: 'number',
|
||||
enumOptions: null,
|
||||
relations: <RelationInfo[]>[]
|
||||
})
|
||||
let result = await driver.GetCoulmnsFromEntity(entities, 'schema');
|
||||
|
@ -78,8 +78,8 @@ export class Post {
|
||||
@Column("longtext")
|
||||
longtext: string;
|
||||
|
||||
// @Column("enum", { enum: ["A", "B", "C"] })
|
||||
// enum: string;
|
||||
@Column("enum", { enum: ["A", "B", "C"] })
|
||||
enum: string;
|
||||
|
||||
// @Column("enum", { enum: FruitEnum })
|
||||
// classEnum1: FruitEnum;
|
||||
|
@ -78,8 +78,8 @@ export class Post {
|
||||
@Column("longtext")
|
||||
longtext: string;
|
||||
|
||||
// @Column("enum", { enum: ["A", "B", "C"] })
|
||||
// enum: string;
|
||||
@Column("enum", { enum: ["A", "B", "C"] })
|
||||
enum: string;
|
||||
|
||||
// @Column("enum", { enum: FruitEnum })
|
||||
// classEnum1: FruitEnum;
|
||||
|
Loading…
Reference in New Issue
Block a user