Import enums from source
This commit is contained in:
parent
5b18b02946
commit
dd2aafe80b
@ -10,6 +10,7 @@ import { useState } from "react";
|
|||||||
import { db } from "../../../data/db";
|
import { db } from "../../../data/db";
|
||||||
import {
|
import {
|
||||||
useAreas,
|
useAreas,
|
||||||
|
useEnums,
|
||||||
useNotes,
|
useNotes,
|
||||||
useSettings,
|
useSettings,
|
||||||
useTables,
|
useTables,
|
||||||
@ -34,6 +35,7 @@ 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";
|
import { importSQL } from "../../../utils/importSQL";
|
||||||
|
import { databases } from "../../../data/databases";
|
||||||
|
|
||||||
const languageExtension = {
|
const languageExtension = {
|
||||||
sql: [sql()],
|
sql: [sql()],
|
||||||
@ -58,6 +60,7 @@ export default function Modal({
|
|||||||
const { setAreas } = useAreas();
|
const { setAreas } = useAreas();
|
||||||
const { setTypes } = useTypes();
|
const { setTypes } = useTypes();
|
||||||
const { settings } = useSettings();
|
const { settings } = useSettings();
|
||||||
|
const { setEnums } = useEnums();
|
||||||
const { setTransform } = useTransform();
|
const { setTransform } = useTransform();
|
||||||
const { setUndoStack, setRedoStack } = useUndoRedo();
|
const { setUndoStack, setRedoStack } = useUndoRedo();
|
||||||
const [importSource, setImportSource] = useState({
|
const [importSource, setImportSource] = useState({
|
||||||
@ -149,7 +152,8 @@ export default function Modal({
|
|||||||
setTransform((prev) => ({ ...prev, pan: { x: 0, y: 0 } }));
|
setTransform((prev) => ({ ...prev, pan: { x: 0, y: 0 } }));
|
||||||
setNotes([]);
|
setNotes([]);
|
||||||
setAreas([]);
|
setAreas([]);
|
||||||
setTypes(d.types ?? []);
|
if (databases[database].hasTypes) setTypes(d.types ?? []);
|
||||||
|
if (databases[database].hasEnums) setEnums(d.enums ?? []);
|
||||||
setUndoStack([]);
|
setUndoStack([]);
|
||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,6 +21,7 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) {
|
|||||||
const tables = [];
|
const tables = [];
|
||||||
const relationships = [];
|
const relationships = [];
|
||||||
const types = [];
|
const types = [];
|
||||||
|
const enums = [];
|
||||||
|
|
||||||
ast.forEach((e) => {
|
ast.forEach((e) => {
|
||||||
if (e.type === "create") {
|
if (e.type === "create") {
|
||||||
@ -176,6 +177,14 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (found !== -1) tables[found].indices.forEach((i, j) => (i.id = j));
|
if (found !== -1) tables[found].indices.forEach((i, j) => (i.id = j));
|
||||||
|
} else if (e.keyword === "type") {
|
||||||
|
if (e.resource === "enum") {
|
||||||
|
const newEnum = {
|
||||||
|
name: e.name.name,
|
||||||
|
values: e.create_definitions.value.map((x) => x.value),
|
||||||
|
};
|
||||||
|
enums.push(newEnum);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else if (e.type === "alter") {
|
} else if (e.type === "alter") {
|
||||||
e.expr.forEach((expr) => {
|
e.expr.forEach((expr) => {
|
||||||
@ -242,5 +251,5 @@ export function fromPostgres(ast, diagramDb = DB.GENERIC) {
|
|||||||
|
|
||||||
relationships.forEach((r, i) => (r.id = i));
|
relationships.forEach((r, i) => (r.id = i));
|
||||||
|
|
||||||
return { tables, relationships, types };
|
return { tables, relationships, types, enums };
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,8 @@ function checkDefault(field, database) {
|
|||||||
|
|
||||||
if (!field.notNull && field.default.toLowerCase() === "null") return true;
|
if (!field.notNull && field.default.toLowerCase() === "null") return true;
|
||||||
|
|
||||||
|
if(!dbToTypes[database][field.type].checkDefault) return true;
|
||||||
|
|
||||||
return dbToTypes[database][field.type].checkDefault(field);
|
return dbToTypes[database][field.type].checkDefault(field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user