Skip to content

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

Fix import failing on single statements (#244)

1ilitb5e23fef2010
diff --git a/src/utils/importSQL/mariadb.js b/src/utils/importSQL/mariadb.js
index 29a06e51..77461755 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 8f3f562f..bb7a95e5 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 a4fbf07e..e8297273 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 5ff0482d..5c77d7b5 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 55e503b2..f2792198 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));