mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-05-24 18:39:12 +00:00
Set up multiple imports for generic diagrams
This commit is contained in:
parent
73dff50f14
commit
6c1ff1518f
@ -740,7 +740,30 @@ export default function ControlPanel({
|
|||||||
shortcut: "Ctrl+I",
|
shortcut: "Ctrl+I",
|
||||||
},
|
},
|
||||||
import_from_source: {
|
import_from_source: {
|
||||||
function: () => setModal(MODAL.IMPORT_SRC),
|
...(database === DB.GENERIC && {
|
||||||
|
children: [
|
||||||
|
{
|
||||||
|
MySQL: () => setModal(MODAL.IMPORT_SRC),
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// PostgreSQL: () => setModal(MODAL.IMPORT_SRC),
|
||||||
|
// },
|
||||||
|
{
|
||||||
|
SQLite: () => setModal(MODAL.IMPORT_SRC),
|
||||||
|
},
|
||||||
|
// {
|
||||||
|
// MariaDB: () => setModal(MODAL.IMPORT_SRC),
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// MSSQL: () => setModal(MODAL.IMPORT_SRC),
|
||||||
|
// },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
function: () => {
|
||||||
|
if (database === DB.GENERIC) return;
|
||||||
|
|
||||||
|
setModal(MODAL.IMPORT_SRC)
|
||||||
|
},
|
||||||
},
|
},
|
||||||
export_as: {
|
export_as: {
|
||||||
children: [
|
children: [
|
||||||
|
@ -19,7 +19,6 @@ import {
|
|||||||
} from "../../../hooks";
|
} from "../../../hooks";
|
||||||
import { saveAs } from "file-saver";
|
import { saveAs } from "file-saver";
|
||||||
import { Parser } from "node-sql-parser";
|
import { Parser } from "node-sql-parser";
|
||||||
import { astToDiagram } from "../../../utils/astToDiagram";
|
|
||||||
import { getModalTitle, getOkText } from "../../../utils/modalTitles";
|
import { getModalTitle, getOkText } from "../../../utils/modalTitles";
|
||||||
import Rename from "./Rename";
|
import Rename from "./Rename";
|
||||||
import Open from "./Open";
|
import Open from "./Open";
|
||||||
@ -34,6 +33,7 @@ import { vscodeDark } from "@uiw/codemirror-theme-vscode";
|
|||||||
import { json } from "@codemirror/lang-json";
|
import { json } from "@codemirror/lang-json";
|
||||||
import { githubLight } from "@uiw/codemirror-theme-github";
|
import { githubLight } from "@uiw/codemirror-theme-github";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { importSQL } from "../../../utils/importSQL";
|
||||||
|
|
||||||
const languageExtension = {
|
const languageExtension = {
|
||||||
sql: [sql()],
|
sql: [sql()],
|
||||||
@ -136,7 +136,7 @@ export default function Modal({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const d = astToDiagram(ast);
|
const d = importSQL(ast);
|
||||||
if (importSource.overwrite) {
|
if (importSource.overwrite) {
|
||||||
setTables(d.tables);
|
setTables(d.tables);
|
||||||
setRelationships(d.relationships);
|
setRelationships(d.relationships);
|
||||||
|
19
src/utils/importSQL/index.js
Normal file
19
src/utils/importSQL/index.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import { DB } from "../../data/constants";
|
||||||
|
import { fromMySQL } from "./mysql";
|
||||||
|
|
||||||
|
export function importSQL(ast, database = DB.MYSQL) {
|
||||||
|
switch (database) {
|
||||||
|
case DB.SQLITE:
|
||||||
|
return { tables: [], relationships: [] };
|
||||||
|
case DB.MYSQL:
|
||||||
|
return fromMySQL(ast);
|
||||||
|
case DB.POSTGRES:
|
||||||
|
return { tables: [], relationships: [] };
|
||||||
|
case DB.MARIADB:
|
||||||
|
return { tables: [], relationships: [] };
|
||||||
|
case DB.MSSQL:
|
||||||
|
return { tables: [], relationships: [] };
|
||||||
|
default:
|
||||||
|
return { tables: [], relationships: [] };
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,7 @@ import {
|
|||||||
tableColorStripHeight,
|
tableColorStripHeight,
|
||||||
tableFieldHeight,
|
tableFieldHeight,
|
||||||
tableHeaderHeight,
|
tableHeaderHeight,
|
||||||
} from "../data/constants";
|
} from "../../data/constants";
|
||||||
|
|
||||||
function buildSQLFromAST(ast) {
|
function buildSQLFromAST(ast) {
|
||||||
if (ast.type === "binary_expr") {
|
if (ast.type === "binary_expr") {
|
||||||
@ -41,7 +41,7 @@ function buildSQLFromAST(ast) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function astToDiagram(ast) {
|
export function fromMySQL(ast) {
|
||||||
const tables = [];
|
const tables = [];
|
||||||
const relationships = [];
|
const relationships = [];
|
||||||
|
|
Loading…
Reference in New Issue
Block a user