Import from mysql

This commit is contained in:
1ilit 2024-06-16 00:23:48 +03:00
parent 1d1dde27e7
commit 0a108fc33a
3 changed files with 15 additions and 4 deletions

View File

@ -35,7 +35,7 @@ export default function TablesContextProvider({ children }) {
fields: [
{
name: "id",
type: "INT",
type: "INTEGER",
default: "",
check: "",
primary: true,

View File

@ -901,7 +901,7 @@ export const mariadbTypes = {
export const mssqlTypes = {
BIGINT: { type: "", checkDefault: (field) => {} },
INT: { type: "", checkDefault: (field) => {} },
INTEGER: { type: "", checkDefault: (field) => {} },
SMALLINT: { type: "", checkDefault: (field) => {} },
TINYINT: { type: "", checkDefault: (field) => {} },
BIT: { type: "", checkDefault: (field) => {} },

View File

@ -1,7 +1,12 @@
import { Cardinality, DB } from "../../data/constants";
import { dbToTypes } from "../../data/datatypes";
import { buildSQLFromAST } from "./shared";
// eslint-disable-next-line no-unused-vars
export const affinity = new Proxy(
{ INT: "INTEGER" },
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
);
export function fromMySQL(ast, diagramDb = DB.GENERIC) {
const tables = [];
const relationships = [];
@ -20,7 +25,13 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) {
if (d.resource === "column") {
const field = {};
field.name = d.column.column;
field.type = d.definition.dataType;
let type = d.definition.dataType;
if (!dbToTypes[diagramDb][type]) {
type = affinity[type];
}
field.type = type;
if (d.definition.expr && d.definition.expr.type === "expr_list") {
field.values = d.definition.expr.value.map((v) => v.value);
}