Allow self references

This commit is contained in:
1ilit 2024-02-06 00:42:11 +02:00
parent 1f84e36f8c
commit 604bed67dd
4 changed files with 34 additions and 18 deletions

View File

@ -46,7 +46,8 @@ import {
jsonToMySQL, jsonToMySQL,
jsonToPostgreSQL, jsonToPostgreSQL,
jsonToSQLite, jsonToSQLite,
jsonToMariaDB jsonToMariaDB,
jsonToSQLServer
} from "../utils"; } from "../utils";
import { import {
AreaContext, AreaContext,
@ -1010,7 +1011,21 @@ export default function ControlPanel({
})); }));
}, },
}, },
{ DBML: () => { } }, {
"SQL Server": () => {
setVisible(MODAL.CODE);
const src = jsonToSQLServer({
tables: tables,
references: relationships,
types: types,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
}
},
], ],
function: () => { }, function: () => { },
}, },

View File

@ -3,7 +3,7 @@ import { templateSeeds } from "./seeds";
const db = new Dexie("drawDB"); const db = new Dexie("drawDB");
db.version(2).stores({ db.version(3).stores({
diagrams: "++id, lastModified", diagrams: "++id, lastModified",
templates: "++id, custom", templates: "++id, custom",
}); });

View File

@ -420,20 +420,16 @@ export default function Editor() {
if (updateRelationships) { if (updateRelationships) {
setRelationships((prev) => setRelationships((prev) =>
prev.map((r) => { prev.map((r) => {
let newR = { ...r };
if (r.startTableId === id) { if (r.startTableId === id) {
return { newR.startX = updatedValues.x + 15;
...r, newR.startY = updatedValues.y + r.startFieldId * 36 + 69;
startX: updatedValues.x + 15,
startY: updatedValues.y + r.startFieldId * 36 + 69,
};
} else if (r.endTableId === id) {
return {
...r,
endX: updatedValues.x + 15,
endY: updatedValues.y + r.endFieldId * 36 + 69,
};
} }
return r; if (r.endTableId === id) {
newR.endX = updatedValues.x + 15;
newR.endY = updatedValues.y + r.endFieldId * 36 + 69;
}
return newR;
}) })
); );
} }

View File

@ -433,6 +433,10 @@ function jsonToMariaDB(obj) {
.join("\n")}`; .join("\n")}`;
} }
function jsonToSQLServer(obj) {
return "TODO";
}
function arrayIsEqual(arr1, arr2) { function arrayIsEqual(arr1, arr2) {
return JSON.stringify(arr1) === JSON.stringify(arr2); return JSON.stringify(arr1) === JSON.stringify(arr2);
} }
@ -702,9 +706,9 @@ function validateDiagram(diagram) {
visited.push(tableId); visited.push(tableId);
visitedTables.add(tableId); visitedTables.add(tableId);
diagram.relationships.forEach((relationship) => { diagram.relationships.forEach((r) => {
if (relationship.startTableId === tableId) { if (r.startTableId === tableId && r.startTableId !== r.endTableId) {
checkCircularRelationships(relationship.endTableId, [...visited]); checkCircularRelationships(r.endTableId, [...visited]);
} }
}); });
} }
@ -815,4 +819,5 @@ export {
calcPath, calcPath,
jsonToSQLite, jsonToSQLite,
jsonToMariaDB, jsonToMariaDB,
jsonToSQLServer,
}; };