Skip to content

Commit

Permalink
properly map mysql json type
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed Dec 9, 2024
1 parent 80f6d91 commit 9d41e60
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion electron/drivers/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,37 @@ enum MySQLType {
MYSQL_TYPE_GEOMETRY = 255,
}

const mapDataName: Record<number, string> = {
0x00: "DECIMAL", // aka DECIMAL
0x01: "TINY", // aka TINYINT, 1 byte
0x02: "SHORT", // aka SMALLINT, 2 bytes
0x03: "LONG", // aka INT, 4 bytes
0x04: "FLOAT", // aka FLOAT, 4-8 bytes
0x05: "DOUBLE", // aka DOUBLE, 8 bytes
0x06: "NULL", // NULL (used for prepared statements, I think)
0x07: "TIMESTAMP", // aka TIMESTAMP
0x08: "LONGLONG", // aka BIGINT, 8 bytes
0x09: "INT24", // aka MEDIUMINT, 3 bytes
0x0a: "DATE", // aka DATE
0x0b: "TIME", // aka TIME
0x0c: "DATETIME", // aka DATETIME
0x0d: "YEAR", // aka YEAR, 1 byte (don't ask)
0x0e: "NEWDATE", // aka ?
0x0f: "VARCHAR", // aka VARCHAR (?)
0x10: "BIT", // aka BIT, 1-8 byte
0xf5: "JSON",
0xf6: "NEWDECIMAL", // aka DECIMAL
0xf7: "ENUM", // aka ENUM
0xf8: "SET", // aka SET
0xf9: "TINY_BLOB", // aka TINYBLOB, TINYTEXT
0xfa: "MEDIUM_BLOB", // aka MEDIUMBLOB, MEDIUMTEXT
0xfb: "LONG_BLOB", // aka LONGBLOG, LONGTEXT
0xfc: "BLOB", // aka BLOB, TEXT
0xfd: "VAR_STRING", // aka VARCHAR, VARBINARY
0xfe: "STRING", // aka CHAR, BINARY
0xff: "GEOMETRY", // aka GEOMETRY
};

function mapDataType(columnType: number): ColumnType {
// List of all column type
// https://dev.mysql.com/doc/dev/mysql-server/latest/field__types_8h_source.html
Expand Down Expand Up @@ -182,7 +213,7 @@ export default class MySQLDriver implements BaseDriver {
return {
displayName: raw.name,
name: renameColName,
originalType: (raw.type.toString() ?? "").toLowerCase(),
originalType: (mapDataName[raw.type] ?? "text").toLowerCase(),
type: mapDataType(raw.type),
};
},
Expand Down

0 comments on commit 9d41e60

Please sign in to comment.