From 604bed67dd4e27a324553710f0c6fe523c5198a3 Mon Sep 17 00:00:00 2001 From: 1ilit Date: Tue, 6 Feb 2024 00:42:11 +0200 Subject: [PATCH] Allow self references --- src/components/ControlPanel.jsx | 19 +++++++++++++++++-- src/data/db.js | 2 +- src/pages/Editor.jsx | 20 ++++++++------------ src/utils/index.js | 11 ++++++++--- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/src/components/ControlPanel.jsx b/src/components/ControlPanel.jsx index a4470b1..c10abf7 100644 --- a/src/components/ControlPanel.jsx +++ b/src/components/ControlPanel.jsx @@ -46,7 +46,8 @@ import { jsonToMySQL, jsonToPostgreSQL, jsonToSQLite, - jsonToMariaDB + jsonToMariaDB, + jsonToSQLServer } from "../utils"; import { 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: () => { }, }, diff --git a/src/data/db.js b/src/data/db.js index db1ba0a..49d5af5 100644 --- a/src/data/db.js +++ b/src/data/db.js @@ -3,7 +3,7 @@ import { templateSeeds } from "./seeds"; const db = new Dexie("drawDB"); -db.version(2).stores({ +db.version(3).stores({ diagrams: "++id, lastModified", templates: "++id, custom", }); diff --git a/src/pages/Editor.jsx b/src/pages/Editor.jsx index 71eb53c..b3e6d5f 100644 --- a/src/pages/Editor.jsx +++ b/src/pages/Editor.jsx @@ -420,20 +420,16 @@ export default function Editor() { if (updateRelationships) { setRelationships((prev) => prev.map((r) => { + let newR = { ...r }; if (r.startTableId === id) { - return { - ...r, - 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, - }; + newR.startX = updatedValues.x + 15; + newR.startY = updatedValues.y + r.startFieldId * 36 + 69; } - return r; + if (r.endTableId === id) { + newR.endX = updatedValues.x + 15; + newR.endY = updatedValues.y + r.endFieldId * 36 + 69; + } + return newR; }) ); } diff --git a/src/utils/index.js b/src/utils/index.js index 006dde0..418ccde 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -433,6 +433,10 @@ function jsonToMariaDB(obj) { .join("\n")}`; } +function jsonToSQLServer(obj) { + return "TODO"; +} + function arrayIsEqual(arr1, arr2) { return JSON.stringify(arr1) === JSON.stringify(arr2); } @@ -702,9 +706,9 @@ function validateDiagram(diagram) { visited.push(tableId); visitedTables.add(tableId); - diagram.relationships.forEach((relationship) => { - if (relationship.startTableId === tableId) { - checkCircularRelationships(relationship.endTableId, [...visited]); + diagram.relationships.forEach((r) => { + if (r.startTableId === tableId && r.startTableId !== r.endTableId) { + checkCircularRelationships(r.endTableId, [...visited]); } }); } @@ -815,4 +819,5 @@ export { calcPath, jsonToSQLite, jsonToMariaDB, + jsonToSQLServer, };