diff --git a/src/utils/importSQL/mariadb.js b/src/utils/importSQL/mariadb.js index 29a06e5..7746175 100644 --- a/src/utils/importSQL/mariadb.js +++ b/src/utils/importSQL/mariadb.js @@ -23,7 +23,7 @@ export function fromMariaDB(ast, diagramDb = DB.GENERIC) { const tables = []; const relationships = []; - ast.forEach((e) => { + const parseSingleStatement = (e) => { if (e.type === "create") { if (e.keyword === "table") { const table = {}; @@ -250,7 +250,13 @@ export function fromMariaDB(ast, diagramDb = DB.GENERIC) { } }); } - }); + }; + + if (Array.isArray(ast)) { + ast.forEach((e) => parseSingleStatement(e)); + } else { + parseSingleStatement(ast); + } relationships.forEach((r, i) => (r.id = i)); diff --git a/src/utils/importSQL/mssql.js b/src/utils/importSQL/mssql.js index 8f3f562..bb7a95e 100644 --- a/src/utils/importSQL/mssql.js +++ b/src/utils/importSQL/mssql.js @@ -9,7 +9,7 @@ const affinity = { ), [DB.GENERIC]: new Proxy( { - INT: "INTEGER", + INTEGER: "INT", TINYINT: "SMALLINT", MEDIUMINT: "INTEGER", BIT: "BOOLEAN", diff --git a/src/utils/importSQL/mysql.js b/src/utils/importSQL/mysql.js index a4fbf07..e829727 100644 --- a/src/utils/importSQL/mysql.js +++ b/src/utils/importSQL/mysql.js @@ -9,7 +9,7 @@ const affinity = { ), [DB.GENERIC]: new Proxy( { - INT: "INTEGER", + INTEGER: "INT", TINYINT: "SMALLINT", MEDIUMINT: "INTEGER", BIT: "BOOLEAN", @@ -23,7 +23,7 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { const tables = []; const relationships = []; - ast.forEach((e) => { + const parseSingleStatement = (e) => { if (e.type === "create") { if (e.keyword === "table") { const table = {}; @@ -250,7 +250,13 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) { } }); } - }); + }; + + if (Array.isArray(ast)) { + ast.forEach((e) => parseSingleStatement(e)); + } else { + parseSingleStatement(ast); + } relationships.forEach((r, i) => (r.id = i)); diff --git a/src/utils/importSQL/postgres.js b/src/utils/importSQL/postgres.js index 5ff0482..5c77d7b 100644 --- a/src/utils/importSQL/postgres.js +++ b/src/utils/importSQL/postgres.js @@ -9,7 +9,7 @@ const affinity = { ), [DB.GENERIC]: new Proxy( { - INT: "INTEGER", + INTEGER: "INT", MEDIUMINT: "INTEGER", BIT: "BOOLEAN", }, @@ -23,7 +23,7 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { const types = []; const enums = []; - ast.forEach((e) => { + const parseSingleStatement = (e) => { if (e.type === "create") { if (e.keyword === "table") { const table = {}; @@ -315,7 +315,13 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) { } }); } - }); + }; + + if (Array.isArray(ast)) { + ast.forEach((e) => parseSingleStatement(e)); + } else { + parseSingleStatement(ast); + } relationships.forEach((r, i) => (r.id = i)); diff --git a/src/utils/importSQL/sqlite.js b/src/utils/importSQL/sqlite.js index 55e503b..f279219 100644 --- a/src/utils/importSQL/sqlite.js +++ b/src/utils/importSQL/sqlite.js @@ -23,7 +23,7 @@ const affinity = { ), [DB.GENERIC]: new Proxy( { - INT: "INTEGER", + INTEGER: "INT", TINYINT: "SMALLINT", MEDIUMINT: "INTEGER", INT2: "INTEGER", @@ -40,7 +40,7 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) { const tables = []; const relationships = []; - ast.forEach((e) => { + const parseSingleStatement = (e) => { if (e.type === "create") { if (e.keyword === "table") { const table = {}; @@ -201,7 +201,13 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) { if (found !== -1) tables[found].indices.forEach((i, j) => (i.id = j)); } } - }); + }; + + if (Array.isArray(ast)) { + ast.forEach((e) => parseSingleStatement(e)); + } else { + parseSingleStatement(ast); + } relationships.forEach((r, i) => (r.id = i));