Import SQLite source

This commit is contained in:
1ilit
2024-06-14 01:00:47 +03:00
parent c0584f11c6
commit e61757f93d
7 changed files with 328 additions and 99 deletions

View File

@@ -76,6 +76,7 @@ export default function ControlPanel({
const [sidesheet, setSidesheet] = useState(SIDESHEET.NONE);
const [prevTitle, setPrevTitle] = useState(title);
const [showEditName, setShowEditName] = useState(false);
const [importDb, setImportDb] = useState("");
const [exportData, setExportData] = useState({
data: null,
filename: `${title}_${new Date().toISOString()}`,
@@ -743,13 +744,19 @@ export default function ControlPanel({
...(database === DB.GENERIC && {
children: [
{
MySQL: () => setModal(MODAL.IMPORT_SRC),
MySQL: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.MYSQL);
},
},
// {
// PostgreSQL: () => setModal(MODAL.IMPORT_SRC),
// },
{
SQLite: () => setModal(MODAL.IMPORT_SRC),
SQLite: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.SQLITE);
},
},
// {
// MariaDB: () => setModal(MODAL.IMPORT_SRC),
@@ -762,7 +769,7 @@ export default function ControlPanel({
function: () => {
if (database === DB.GENERIC) return;
setModal(MODAL.IMPORT_SRC)
setModal(MODAL.IMPORT_SRC);
},
},
export_as: {
@@ -1260,6 +1267,7 @@ export default function ControlPanel({
setDiagramId={setDiagramId}
setModal={setModal}
prevTitle={prevTitle}
importDb={importDb}
/>
<Sidesheet
type={sidesheet}

View File

@@ -50,9 +50,10 @@ export default function Modal({
setDiagramId,
exportData,
setExportData,
importDb,
}) {
const { t } = useTranslation();
const { setTables, setRelationships, setDatabase } = useTables();
const { setTables, setRelationships, database, setDatabase } = useTables();
const { setNotes } = useNotes();
const { setAreas } = useAreas();
const { setTypes } = useTypes();
@@ -62,7 +63,6 @@ export default function Modal({
const [importSource, setImportSource] = useState({
src: "",
overwrite: true,
dbms: "MySQL",
});
const [importData, setImportData] = useState(null);
const [error, setError] = useState({
@@ -120,7 +120,9 @@ export default function Modal({
const parser = new Parser();
let ast = null;
try {
ast = parser.astify(importSource.src, { database: "MySQL" });
ast = parser.astify(importSource.src, {
database: database === DB.GENERIC ? importDb : database,
});
} catch (err) {
setError({
type: STATUS.ERROR,
@@ -136,7 +138,7 @@ export default function Modal({
return;
}
const d = importSQL(ast);
const d = importSQL(ast, database === DB.GENERIC ? importDb : database, database);
if (importSource.overwrite) {
setTables(d.tables);
setRelationships(d.relationships);
@@ -316,7 +318,6 @@ export default function Modal({
setImportSource({
src: "",
overwrite: true,
dbms: "MySQL",
});
}}
onCancel={() => {