diff --git a/src/context/TablesContext.jsx b/src/context/TablesContext.jsx index bba9344..fd3c6bc 100644 --- a/src/context/TablesContext.jsx +++ b/src/context/TablesContext.jsx @@ -35,7 +35,7 @@ export default function TablesContextProvider({ children }) { fields: [ { name: "id", - type: "INT", + type: "INTEGER", default: "", check: "", primary: true, diff --git a/src/data/datatypes.js b/src/data/datatypes.js index 80391c4..0875e85 100644 --- a/src/data/datatypes.js +++ b/src/data/datatypes.js @@ -901,7 +901,7 @@ export const mariadbTypes = { export const mssqlTypes = { BIGINT: { type: "", checkDefault: (field) => {} }, - INT: { type: "", checkDefault: (field) => {} }, + INTEGER: { type: "", checkDefault: (field) => {} }, SMALLINT: { type: "", checkDefault: (field) => {} }, TINYINT: { type: "", checkDefault: (field) => {} }, BIT: { type: "", checkDefault: (field) => {} }, diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js index fb54612..fbea6ab 100644 --- a/src/utils/importSQL/mysql.js +++ b/src/utils/importSQL/mysql.js @@ -1,7 +1,12 @@ import { Cardinality, DB } from "../../data/constants"; +import { dbToTypes } from "../../data/datatypes"; import { buildSQLFromAST } from "./shared"; -// eslint-disable-next-line no-unused-vars +export const affinity = new Proxy( + { INT: "INTEGER" }, + { get: (target, prop) => (prop in target ? target[prop] : "BLOB") }, +); + export function fromMySQL(ast, diagramDb = DB.GENERIC) { const tables = []; const relationships = []; @@ -20,7 +25,13 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { if (d.resource === "column") { const field = {}; field.name = d.column.column; - field.type = d.definition.dataType; + + let type = d.definition.dataType; + if (!dbToTypes[diagramDb][type]) { + type = affinity[type]; + } + field.type = type; + if (d.definition.expr && d.definition.expr.type === "expr_list") { field.values = d.definition.expr.value.map((v) => v.value); }