Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Convert unsupported types in generic diagrams on import

1ilit490cb738de86
diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js
index fbea6ab5..a6b674b5 100644
--- a/src/utils/importSQL/mysql.js
+++ b/src/utils/importSQL/mysql.js
@@ -2,10 +2,22 @@ import { Cardinality, DB } from "../../data/constants";
import { dbToTypes } from "../../data/datatypes";
import { buildSQLFromAST } from "./shared";
-export const affinity = new Proxy(
- { INT: "INTEGER" },
- { get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
-);
+const affinity = {
+ [DB.MYSQL]: new Proxy(
+ { INT: "INTEGER" },
+ { get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
+ ),
+ [DB.GENERIC]: new Proxy(
+ {
+ INT: "INTEGER",
+ TINYINT: "SMALLINT",
+ MEDIUMINT: "INTEGER",
+ BIT: "BOOLEAN",
+ YEAR: "INTEGER",
+ },
+ { get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
+ ),
+};
export function fromMySQL(ast, diagramDb = DB.GENERIC) {
const tables = [];
@@ -28,7 +40,7 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) {
let type = d.definition.dataType;
if (!dbToTypes[diagramDb][type]) {
- type = affinity[type];
+ type = affinity[diagramDb][type];
}
field.type = type;
diff --git a/src/utils/importSQL/sqlite.js b/src/utils/importSQL/sqlite.js
index 34260272..7a1c9c3a 100644
--- a/src/utils/importSQL/sqlite.js
+++ b/src/utils/importSQL/sqlite.js
@@ -2,26 +2,39 @@ import { Cardinality, DB } from "../../data/constants";
import { dbToTypes } from "../../data/datatypes";
import { buildSQLFromAST } from "./shared";
-export const affinity = new Proxy(
- {
- INT: "INTEGER",
- TINYINT: "INTEGER",
- SMALLINT: "INTEGER",
- MEDIUMINT: "INTEGER",
- BIGINT: "INTEGER",
- "UNSIGNED BIG INT": "INTEGER",
- INT2: "INTEGER",
- INT8: "INTEGER",
- CHARACTER: "TEXT",
- NCHARACTER: "TEXT",
- NVARCHAR: "VARCHAR",
- DOUBLE: "REAL",
- FLOAT: "REAL",
- },
- {
- get: (target, prop) => (prop in target ? target[prop] : "BLOB"),
- },
-);
+const affinity = {
+ [DB.SQLITE]: new Proxy(
+ {
+ INT: "INTEGER",
+ TINYINT: "INTEGER",
+ SMALLINT: "INTEGER",
+ MEDIUMINT: "INTEGER",
+ BIGINT: "INTEGER",
+ "UNSIGNED BIG INT": "INTEGER",
+ INT2: "INTEGER",
+ INT8: "INTEGER",
+ CHARACTER: "TEXT",
+ NCHARACTER: "TEXT",
+ NVARCHAR: "VARCHAR",
+ DOUBLE: "REAL",
+ FLOAT: "REAL",
+ },
+ { get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
+ ),
+ [DB.GENERIC]: new Proxy(
+ {
+ INT: "INTEGER",
+ TINYINT: "SMALLINT",
+ MEDIUMINT: "INTEGER",
+ INT2: "INTEGER",
+ INT8: "INTEGER",
+ CHARACTER: "TEXT",
+ NCHARACTER: "TEXT",
+ NVARCHAR: "VARCHAR",
+ },
+ { get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
+ ),
+};
export function fromSQLite(ast, diagramDb = DB.GENERIC) {
console.log(ast);
@@ -45,7 +58,7 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) {
let type = d.definition.dataType;
if (!dbToTypes[diagramDb][type]) {
- type = affinity[type];
+ type = affinity[diagramDb][type];
}
field.type = type;