Fix import failing on single statements (#244)

This commit is contained in:
1ilit 2024-09-21 21:24:56 +04:00
parent f635d0774c
commit b5e23fef20
5 changed files with 36 additions and 12 deletions

View File

@ -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));

View File

@ -9,7 +9,7 @@ const affinity = {
),
[DB.GENERIC]: new Proxy(
{
INT: "INTEGER",
INTEGER: "INT",
TINYINT: "SMALLINT",
MEDIUMINT: "INTEGER",
BIT: "BOOLEAN",

View File

@ -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));

View File

@ -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));

View File

@ -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));