support for more(all?) column types in MySQL, MariaDB
This commit is contained in:
parent
2b23d16be5
commit
7cfe6fa721
@ -8,7 +8,7 @@ import { DatabaseModel } from './../models/DatabaseModel'
|
||||
* MysqlDriver
|
||||
*/
|
||||
export class MysqlDriver extends AbstractDriver {
|
||||
readonly EngineName:string = 'MySQL'
|
||||
readonly EngineName: string = 'MySQL'
|
||||
|
||||
FindPrimaryColumnsFromIndexes(dbModel: DatabaseModel) {
|
||||
dbModel.entities.forEach(entity => {
|
||||
@ -64,14 +64,8 @@ export class MysqlDriver extends AbstractDriver {
|
||||
colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null;
|
||||
break;
|
||||
case "tinyint":
|
||||
if (resp.NUMERIC_PRECISION == 3) {
|
||||
colInfo.ts_type = "boolean"
|
||||
colInfo.sql_type = "boolean"
|
||||
} else {
|
||||
colInfo.ts_type = "number"
|
||||
colInfo.sql_type = "smallint"
|
||||
colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null;
|
||||
}
|
||||
colInfo.ts_type = "number"
|
||||
colInfo.sql_type = "tinyint"
|
||||
break;
|
||||
case "smallint":
|
||||
colInfo.ts_type = "number"
|
||||
@ -93,11 +87,11 @@ export class MysqlDriver extends AbstractDriver {
|
||||
colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH : null;
|
||||
break;
|
||||
case "date":
|
||||
colInfo.ts_type = "Date"
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "date"
|
||||
break;
|
||||
case "time":
|
||||
colInfo.ts_type = "Date"
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "time"
|
||||
break;
|
||||
case "datetime":
|
||||
@ -120,6 +114,48 @@ export class MysqlDriver extends AbstractDriver {
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "text"
|
||||
break;
|
||||
|
||||
case "mediumint":
|
||||
colInfo.ts_type = "number"
|
||||
colInfo.sql_type = "mediumint"
|
||||
break;
|
||||
case "timestamp":
|
||||
colInfo.ts_type = "Date"
|
||||
colInfo.sql_type = "timestamp"
|
||||
break;
|
||||
case "year":
|
||||
colInfo.ts_type = "number"
|
||||
colInfo.sql_type = "year"
|
||||
break;
|
||||
case "blob":
|
||||
colInfo.ts_type = "Buffer"
|
||||
colInfo.sql_type = "blob"
|
||||
break;
|
||||
case "tinyblob":
|
||||
colInfo.ts_type = "Buffer"
|
||||
colInfo.sql_type = "tinyblob"
|
||||
break;
|
||||
case "tinytext":
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "tinytext"
|
||||
break;
|
||||
case "mediumblob":
|
||||
colInfo.ts_type = "Buffer"
|
||||
colInfo.sql_type = "mediumblob"
|
||||
break;
|
||||
case "mediumtext":
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "mediumtext"
|
||||
break;
|
||||
case "longblob":
|
||||
colInfo.ts_type = "Buffer"
|
||||
colInfo.sql_type = "longblob"
|
||||
break;
|
||||
case "longtext":
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "longtext"
|
||||
break;
|
||||
|
||||
case "varchar":
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "varchar"
|
||||
@ -155,6 +191,10 @@ export class MysqlDriver extends AbstractDriver {
|
||||
colInfo.ts_type = "string"
|
||||
colInfo.sql_type = "text"
|
||||
break;
|
||||
case "json":
|
||||
colInfo.ts_type = "Object"
|
||||
colInfo.sql_type = "json"
|
||||
break;
|
||||
default:
|
||||
console.error("Unknown column type:" + resp.DATA_TYPE);
|
||||
break;
|
||||
@ -289,15 +329,15 @@ export class MysqlDriver extends AbstractDriver {
|
||||
isOneToMany = false;
|
||||
}
|
||||
let ownerRelation = new RelationInfo()
|
||||
let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')
|
||||
let columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')
|
||||
if (referencedEntity.Columns.filter((filterVal) => {
|
||||
return filterVal.name == columnName;
|
||||
}).length>0){
|
||||
for (let i=2;i<=10;i++){
|
||||
columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '')+i.toString();
|
||||
}).length > 0) {
|
||||
for (let i = 2; i <= 10; i++) {
|
||||
columnName = ownerEntity.EntityName.toLowerCase() + (isOneToMany ? 's' : '') + i.toString();
|
||||
if (referencedEntity.Columns.filter((filterVal) => {
|
||||
return filterVal.name == columnName;
|
||||
}).length==0) break;
|
||||
}).length == 0) break;
|
||||
}
|
||||
}
|
||||
ownerRelation.actionOnDelete = relationTmp.actionOnDelete
|
||||
@ -306,7 +346,7 @@ export class MysqlDriver extends AbstractDriver {
|
||||
ownerRelation.relatedColumn = relatedColumn.name.toLowerCase()
|
||||
ownerRelation.relatedTable = relationTmp.referencedTable
|
||||
ownerRelation.ownerTable = relationTmp.ownerTable
|
||||
ownerRelation.ownerColumn =columnName
|
||||
ownerRelation.ownerColumn = columnName
|
||||
ownerRelation.relationType = isOneToMany ? "ManyToOne" : "OneToOne"
|
||||
ownerColumn.relations.push(ownerRelation)
|
||||
if (isOneToMany) {
|
||||
|
94
test/integration/entityTypes/mariadb/entity/Post.ts
Normal file
94
test/integration/entityTypes/mariadb/entity/Post.ts
Normal file
@ -0,0 +1,94 @@
|
||||
import { Entity, PrimaryColumn, Column } from "typeorm";
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column("int")
|
||||
int: number;
|
||||
|
||||
@Column("tinyint")
|
||||
tinyint: number;
|
||||
|
||||
@Column("smallint")
|
||||
smallint: number;
|
||||
|
||||
@Column("mediumint")
|
||||
mediumint: number;
|
||||
|
||||
@Column("bigint")
|
||||
bigint: number;
|
||||
|
||||
@Column("float")
|
||||
float: number;
|
||||
|
||||
@Column("double")
|
||||
double: number;
|
||||
|
||||
@Column("decimal")
|
||||
decimal: number;
|
||||
|
||||
@Column("date")
|
||||
date: string;
|
||||
|
||||
@Column("datetime")
|
||||
datetime: Date;
|
||||
|
||||
@Column("timestamp")
|
||||
timestamp: Date;
|
||||
|
||||
@Column("time")
|
||||
time: string;
|
||||
|
||||
@Column("year")
|
||||
year: number;
|
||||
|
||||
@Column("char")
|
||||
char: string;
|
||||
|
||||
@Column("varchar")
|
||||
varchar: string;
|
||||
|
||||
@Column("blob")
|
||||
blob: Buffer;
|
||||
|
||||
@Column("text")
|
||||
text: string;
|
||||
|
||||
@Column("tinyblob")
|
||||
tinyblob: Buffer;
|
||||
|
||||
@Column("tinytext")
|
||||
tinytext: string;
|
||||
|
||||
@Column("mediumblob")
|
||||
mediumblob: Buffer;
|
||||
|
||||
@Column("mediumtext")
|
||||
mediumtext: string;
|
||||
|
||||
@Column("longblob")
|
||||
longblob: Buffer;
|
||||
|
||||
@Column("longtext")
|
||||
longtext: string;
|
||||
|
||||
// @Column("enum", { enum: ["A", "B", "C"] })
|
||||
// enum: string;
|
||||
|
||||
// @Column("enum", { enum: FruitEnum })
|
||||
// classEnum1: FruitEnum;
|
||||
|
||||
//MariaDb type for Json - LONGTEXT
|
||||
// @Column("json")
|
||||
// json: Object;
|
||||
|
||||
// @Column("simple-array")
|
||||
// simpleArray: string[];
|
||||
|
||||
}
|
93
test/integration/entityTypes/mysql/entity/Post.ts
Normal file
93
test/integration/entityTypes/mysql/entity/Post.ts
Normal file
@ -0,0 +1,93 @@
|
||||
import { Entity, PrimaryColumn, Column } from "typeorm";
|
||||
|
||||
@Entity("Post")
|
||||
export class Post {
|
||||
|
||||
@PrimaryColumn()
|
||||
id: number;
|
||||
|
||||
@Column()
|
||||
name: string;
|
||||
|
||||
@Column("int")
|
||||
int: number;
|
||||
|
||||
@Column("tinyint")
|
||||
tinyint: number;
|
||||
|
||||
@Column("smallint")
|
||||
smallint: number;
|
||||
|
||||
@Column("mediumint")
|
||||
mediumint: number;
|
||||
|
||||
@Column("bigint")
|
||||
bigint: number;
|
||||
|
||||
@Column("float")
|
||||
float: number;
|
||||
|
||||
@Column("double")
|
||||
double: number;
|
||||
|
||||
@Column("decimal")
|
||||
decimal: number;
|
||||
|
||||
@Column("date")
|
||||
date: string;
|
||||
|
||||
@Column("datetime")
|
||||
datetime: Date;
|
||||
|
||||
@Column("timestamp")
|
||||
timestamp: Date;
|
||||
|
||||
@Column("time")
|
||||
time: string;
|
||||
|
||||
@Column("year")
|
||||
year: number;
|
||||
|
||||
@Column("char")
|
||||
char: string;
|
||||
|
||||
@Column("varchar")
|
||||
varchar: string;
|
||||
|
||||
@Column("blob")
|
||||
blob: Buffer;
|
||||
|
||||
@Column("text")
|
||||
text: string;
|
||||
|
||||
@Column("tinyblob")
|
||||
tinyblob: Buffer;
|
||||
|
||||
@Column("tinytext")
|
||||
tinytext: string;
|
||||
|
||||
@Column("mediumblob")
|
||||
mediumblob: Buffer;
|
||||
|
||||
@Column("mediumtext")
|
||||
mediumtext: string;
|
||||
|
||||
@Column("longblob")
|
||||
longblob: Buffer;
|
||||
|
||||
@Column("longtext")
|
||||
longtext: string;
|
||||
|
||||
// @Column("enum", { enum: ["A", "B", "C"] })
|
||||
// enum: string;
|
||||
|
||||
// @Column("enum", { enum: FruitEnum })
|
||||
// classEnum1: FruitEnum;
|
||||
|
||||
@Column("json")
|
||||
json: Object;
|
||||
|
||||
// @Column("simple-array")
|
||||
// simpleArray: string[];
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user