support for mysql set type (#91)

This commit is contained in:
Kononnable 2019-12-19 17:43:03 +01:00
parent 57cec40afb
commit 7679ef2b77
3 changed files with 33 additions and 2 deletions

View File

@ -75,7 +75,8 @@ export default class MysqlDriver extends AbstractDriver {
};
const generated = resp.IsIdentity === 1 ? true : undefined;
const defaultValue = MysqlDriver.ReturnDefaultValueFunction(
resp.COLUMN_DEFAULT
resp.COLUMN_DEFAULT,
resp.DATA_TYPE
);
let columnType = resp.DATA_TYPE;
if (resp.IS_NULLABLE === "YES") options.nullable = true;
@ -178,6 +179,20 @@ export default class MysqlDriver extends AbstractDriver {
.replace(/'/gi, "")
.split(",");
break;
case "set":
tscType = `(${resp.COLUMN_TYPE.substring(
4,
resp.COLUMN_TYPE.length - 1
)
.replace(/'/gi, '"')
.replace(/","/gi, '" | "')})[]`;
options.enum = resp.COLUMN_TYPE.substring(
4,
resp.COLUMN_TYPE.length - 1
)
.replace(/'/gi, "")
.split(",");
break;
case "json":
tscType = "object";
break;
@ -488,7 +503,8 @@ export default class MysqlDriver extends AbstractDriver {
}
private static ReturnDefaultValueFunction(
defVal: string | undefined
defVal: string | undefined,
dataType: string
): string | undefined {
let defaultValue = defVal;
if (!defaultValue || defaultValue === "NULL") {
@ -503,6 +519,9 @@ export default class MysqlDriver extends AbstractDriver {
) {
return `() => "${defaultValue}"`;
}
if (dataType === "set") {
return `() => ['${defaultValue.split(",").join("','")}']`;
}
return `() => "'${defaultValue}'"`;
}
}

View File

@ -116,4 +116,10 @@ export class Post {
@Column("geometrycollection")
geometrycollection: string;
@Column("set", {
enum: ["A", "B", "C"],
default: ["A", "B"]
})
roles: ("A" | "B" | "C")[]
}

View File

@ -118,4 +118,10 @@ export class Post {
@Column("geometrycollection")
geometrycollection: string;
@Column("set", {
enum: ["A", "B", "C"],
default: ["A", "B"]
})
roles: ("A" | "B" | "C")[]
}