Skip to content

Commit

Permalink
Fix import from sql for mssql
Browse files Browse the repository at this point in the history
  • Loading branch information
1ilit committed Jan 18, 2025
1 parent 5476470 commit f0adcf1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"jsonschema": "^1.4.1",
"jspdf": "^2.5.1",
"lexical": "^0.12.5",
"node-sql-parser": "^5.3.4",
"node-sql-parser": "^5.3.6",
"octokit": "^4.0.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
9 changes: 6 additions & 3 deletions src/utils/importSQL/mssql.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,8 @@ export function fromMSSQL(ast, diagramDb = DB.GENERIC) {
e.expr.forEach((expr) => {
if (
expr.action === "add" &&
expr.create_definitions.constraint_type.toLowerCase() === "foreign key"
expr.create_definitions.constraint_type.toLowerCase() ===
"foreign key"
) {
const relationship = {};
const startTable = e.table[0].table;
Expand Down Expand Up @@ -266,16 +267,18 @@ export function fromMSSQL(ast, diagramDb = DB.GENERIC) {

if (ast.go_next) {
let x = { ...ast };
let done = Array.isArray(x.go_next);
let done = false;
while (!done) {
parseSingleStatement(x.ast);
done = Array.isArray(x.go_next) && x.go_next.length === 0;
x = { ...x.go_next };
done = Array.isArray(x.go_next);
}
} else if (Array.isArray(ast)) {
ast.forEach((e) => {
parseSingleStatement(e);
});
} else if (typeof ast === "object") {
parseSingleStatement(ast);
}

return { tables, relationships };
Expand Down

0 comments on commit f0adcf1

Please sign in to comment.