diff --git a/src/drivers/MssqlDriver.ts b/src/drivers/MssqlDriver.ts index b59ad36..237c05a 100644 --- a/src/drivers/MssqlDriver.ts +++ b/src/drivers/MssqlDriver.ts @@ -80,10 +80,10 @@ export class MssqlDriver extends AbstractDriver { resp.IS_NULLABLE == "YES" ? true : false; colInfo.is_generated = resp.IsIdentity == 1 ? true : false; colInfo.default = resp.COLUMN_DEFAULT; + colInfo.sql_type = resp.DATA_TYPE; switch (resp.DATA_TYPE) { case "int": colInfo.ts_type = "number"; - colInfo.sql_type = "int"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -91,7 +91,6 @@ export class MssqlDriver extends AbstractDriver { break; case "tinyint": colInfo.ts_type = "number"; - colInfo.sql_type = "smallint"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -99,7 +98,6 @@ export class MssqlDriver extends AbstractDriver { break; case "smallint": colInfo.ts_type = "number"; - colInfo.sql_type = "smallint"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -107,11 +105,9 @@ export class MssqlDriver extends AbstractDriver { break; case "bit": colInfo.ts_type = "boolean"; - colInfo.sql_type = "boolean"; break; case "float": colInfo.ts_type = "number"; - colInfo.sql_type = "float"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -120,7 +116,6 @@ export class MssqlDriver extends AbstractDriver { break; case "bigint": colInfo.ts_type = "string"; - colInfo.sql_type = "bigint"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -128,19 +123,15 @@ export class MssqlDriver extends AbstractDriver { 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 = "Date"; - colInfo.sql_type = "datetime"; break; case "char": colInfo.ts_type = "string"; - colInfo.sql_type = "char"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -148,7 +139,6 @@ export class MssqlDriver extends AbstractDriver { break; case "nchar": colInfo.ts_type = "string"; - colInfo.sql_type = "nchar"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -156,19 +146,15 @@ export class MssqlDriver extends AbstractDriver { break; case "text": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "ntext": colInfo.ts_type = "string"; - colInfo.sql_type = "ntext"; break; case "uniqueidentifier": colInfo.ts_type = "string"; - colInfo.sql_type = "uniqueidentifier"; break; case "varchar": colInfo.ts_type = "string"; - colInfo.sql_type = "varchar"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -176,7 +162,6 @@ export class MssqlDriver extends AbstractDriver { break; case "binary": colInfo.ts_type = "Buffer"; - colInfo.sql_type = "binary"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -184,7 +169,6 @@ export class MssqlDriver extends AbstractDriver { break; case "varbinary": colInfo.ts_type = "Buffer"; - colInfo.sql_type = "varbinary"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -192,11 +176,9 @@ export class MssqlDriver extends AbstractDriver { break; case "image": colInfo.ts_type = "Buffer"; - colInfo.sql_type = "image"; break; case "nvarchar": colInfo.ts_type = "string"; - colInfo.sql_type = "nvarchar"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -204,15 +186,12 @@ export class MssqlDriver extends AbstractDriver { break; case "money": colInfo.ts_type = "number"; - colInfo.sql_type = "decimal"; break; case "smallmoney": colInfo.ts_type = "number"; - colInfo.sql_type = "smallmoney"; break; case "real": colInfo.ts_type = "number"; - colInfo.sql_type = "double"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -220,7 +199,6 @@ export class MssqlDriver extends AbstractDriver { break; case "decimal": colInfo.ts_type = "number"; - colInfo.sql_type = "decimal"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; colInfo.numericScale = resp.NUMERIC_SCALE; colInfo.char_max_lenght = @@ -230,7 +208,6 @@ export class MssqlDriver extends AbstractDriver { break; case "numeric": colInfo.ts_type = "number"; - colInfo.sql_type = "numeric"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; colInfo.numericScale = resp.NUMERIC_SCALE; colInfo.char_max_lenght = @@ -240,30 +217,25 @@ export class MssqlDriver extends AbstractDriver { break; case "datetime2": colInfo.ts_type = "Date"; - colInfo.sql_type = "datetime2"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; break; case "time": colInfo.ts_type = "Date"; - colInfo.sql_type = "time"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; break; case "datetimeoffset": colInfo.ts_type = "Date"; - colInfo.sql_type = "datetimeoffset"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; break; case "smalldatetime": colInfo.ts_type = "Date"; - colInfo.sql_type = "smalldatetime"; break; case "xml": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; default: TomgUtils.LogFatalError( - "Unknown column type:" + resp.DATA_TYPE + `Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}` ); break; } diff --git a/src/drivers/MysqlDriver.ts b/src/drivers/MysqlDriver.ts index 74a3087..455b1fa 100644 --- a/src/drivers/MysqlDriver.ts +++ b/src/drivers/MysqlDriver.ts @@ -81,10 +81,10 @@ export class MysqlDriver extends AbstractDriver { resp.IS_NULLABLE == "YES" ? true : false; colInfo.is_generated = resp.IsIdentity == 1 ? true : false; colInfo.default = resp.COLUMN_DEFAULT; + colInfo.sql_type = resp.DATA_TYPE; switch (resp.DATA_TYPE) { case "int": colInfo.ts_type = "number"; - colInfo.sql_type = "int"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -92,11 +92,9 @@ export class MysqlDriver extends AbstractDriver { break; case "tinyint": colInfo.ts_type = "number"; - colInfo.sql_type = "tinyint"; break; case "smallint": colInfo.ts_type = "number"; - colInfo.sql_type = "smallint"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -104,11 +102,9 @@ export class MysqlDriver extends AbstractDriver { break; case "bit": colInfo.ts_type = "boolean"; - colInfo.sql_type = "boolean"; break; case "float": colInfo.ts_type = "number"; - colInfo.sql_type = "float"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -116,7 +112,6 @@ export class MysqlDriver extends AbstractDriver { break; case "bigint": colInfo.ts_type = "number"; - colInfo.sql_type = "bigint"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -124,77 +119,58 @@ export class MysqlDriver extends AbstractDriver { break; case "date": colInfo.ts_type = "string"; - colInfo.sql_type = "date"; break; case "time": colInfo.ts_type = "string"; - colInfo.sql_type = "time"; break; case "datetime": colInfo.ts_type = "Date"; - colInfo.sql_type = "datetime"; break; case "char": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "nchar": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "text": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "ntext": 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"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -202,7 +178,6 @@ export class MysqlDriver extends AbstractDriver { break; case "nvarchar": colInfo.ts_type = "string"; - colInfo.sql_type = "nvarchar"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -210,11 +185,9 @@ export class MysqlDriver extends AbstractDriver { break; case "money": colInfo.ts_type = "number"; - colInfo.sql_type = "decimal"; break; case "real": colInfo.ts_type = "number"; - colInfo.sql_type = "double"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -222,7 +195,6 @@ export class MysqlDriver extends AbstractDriver { break; case "double": colInfo.ts_type = "number"; - colInfo.sql_type = "double"; colInfo.char_max_lenght = resp.CHARACTER_MAXIMUM_LENGTH > 0 ? resp.CHARACTER_MAXIMUM_LENGTH @@ -230,7 +202,6 @@ export class MysqlDriver extends AbstractDriver { break; case "decimal": colInfo.ts_type = "number"; - colInfo.sql_type = "decimal"; colInfo.numericPrecision = resp.NUMERIC_PRECISION; colInfo.numericScale = resp.NUMERIC_SCALE; colInfo.char_max_lenght = @@ -240,22 +211,19 @@ export class MysqlDriver extends AbstractDriver { break; case "xml": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "json": 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 + `Unknown column type: ${resp.DATA_TYPE} table name: ${resp.TABLE_NAME} column name: ${resp.COLUMN_NAME}` ); break; } diff --git a/src/drivers/PostgresDriver.ts b/src/drivers/PostgresDriver.ts index 59edc5b..513957b 100644 --- a/src/drivers/PostgresDriver.ts +++ b/src/drivers/PostgresDriver.ts @@ -86,14 +86,13 @@ export class PostgresDriver extends AbstractDriver { colInfo.default = colInfo.is_generated ? "" : resp.column_default; + colInfo.sql_type = resp.data_type; switch (resp.data_type) { case "integer": colInfo.ts_type = "number"; - colInfo.sql_type = "int"; break; case "character varying": colInfo.ts_type = "string"; - colInfo.sql_type = "varchar"; colInfo.char_max_lenght = resp.character_maximum_length > 0 ? resp.character_maximum_length @@ -101,77 +100,60 @@ export class PostgresDriver extends AbstractDriver { break; case "text": colInfo.ts_type = "string"; - colInfo.sql_type = "text"; break; case "uuid": colInfo.ts_type = "string"; - colInfo.sql_type = "uuid"; break; case "smallint": colInfo.ts_type = "number"; - colInfo.sql_type = "smallint"; break; case "bigint": colInfo.ts_type = "string"; - colInfo.sql_type = "bigint"; break; case "date": colInfo.ts_type = "string"; - colInfo.sql_type = "date"; break; case "boolean": colInfo.ts_type = "boolean"; - colInfo.sql_type = "boolean"; break; case "double precision": colInfo.ts_type = "number"; - colInfo.sql_type = "double"; colInfo.numericPrecision = resp.numeric_precision; colInfo.numericScale = resp.numeric_scale; break; case "real": colInfo.ts_type = "number"; - colInfo.sql_type = "float"; colInfo.numericPrecision = resp.numeric_precision; colInfo.numericScale = resp.numeric_scale; break; case "numeric": colInfo.ts_type = "string"; - colInfo.sql_type = "numeric"; colInfo.numericPrecision = resp.numeric_precision; colInfo.numericScale = resp.numeric_scale; break; case "time without time zone": colInfo.ts_type = "string"; - colInfo.sql_type = "time without time zone"; break; case "timestamp without time zone": colInfo.ts_type = "Date"; - colInfo.sql_type = "timestamp"; break; case "timestamp with time zone": colInfo.ts_type = "Date"; - colInfo.sql_type = "timestamp"; break; case "timestamp with time zone": colInfo.ts_type = "Date"; - colInfo.sql_type = "timestamp"; break; case "json": colInfo.ts_type = "Object"; - colInfo.sql_type = "json"; break; case "jsonb": colInfo.ts_type = "Object"; - colInfo.sql_type = "jsonb"; break; case "money": colInfo.ts_type = "string"; - colInfo.sql_type = "money"; break; case "character": colInfo.ts_type = "string"; - colInfo.sql_type = "character"; colInfo.char_max_lenght = resp.character_maximum_length > 0 ? resp.character_maximum_length @@ -179,71 +161,55 @@ export class PostgresDriver extends AbstractDriver { break; case "bytea": colInfo.ts_type = "Buffer"; - colInfo.sql_type = "bytea"; break; case "interval": colInfo.ts_type = "any"; - colInfo.sql_type = "interval"; break; case "time with time zone": colInfo.ts_type = "string"; - colInfo.sql_type = "time with time zone"; break; case "point": colInfo.ts_type = "string | Object"; - colInfo.sql_type = "point"; break; case "line": colInfo.ts_type = "string"; - colInfo.sql_type = "line"; break; case "lseg": colInfo.ts_type = "string | string[]"; - colInfo.sql_type = "lseg"; break; case "box": colInfo.ts_type = "string | Object"; - colInfo.sql_type = "box"; break; case "path": colInfo.ts_type = "string"; - colInfo.sql_type = "path"; break; case "polygon": colInfo.ts_type = "string"; - colInfo.sql_type = "polygon"; break; case "circle": colInfo.ts_type = "string | Object"; - colInfo.sql_type = "circle"; break; case "cidr": colInfo.ts_type = "string"; - colInfo.sql_type = "cidr"; break; case "inet": colInfo.ts_type = "string"; - colInfo.sql_type = "inet"; break; case "macaddr": colInfo.ts_type = "string"; - colInfo.sql_type = "macaddr"; break; case "bit": colInfo.ts_type = "string"; - colInfo.sql_type = "bit"; break; case "bit varying": colInfo.ts_type = "string"; - colInfo.sql_type = "bit varying"; break; case "xml": colInfo.ts_type = "string"; - colInfo.sql_type = "xml"; break; default: TomgUtils.LogFatalError( - "Unknown column type:" + resp.data_type + `Unknown column type: ${resp.data_type} table name: ${resp.table_name} column name: ${resp.column_name}` ); break; } diff --git a/src/models/ColumnInfo.ts b/src/models/ColumnInfo.ts index fed4491..2dc3461 100644 --- a/src/models/ColumnInfo.ts +++ b/src/models/ColumnInfo.ts @@ -17,7 +17,7 @@ export class ColumnInfo { | "string | Object" | "string | string[]" | "any"; - sql_type: ColumnType; + sql_type: string; char_max_lenght: number | null = null; isPrimary: boolean = false; is_generated: boolean = false;