mirror of
https://github.com/drawdb-io/drawdb.git
synced 2025-12-21 01:07:24 +08:00
Convert unsupported types in generic diagrams on import
This commit is contained in:
@@ -2,10 +2,22 @@ import { Cardinality, DB } from "../../data/constants";
|
|||||||
import { dbToTypes } from "../../data/datatypes";
|
import { dbToTypes } from "../../data/datatypes";
|
||||||
import { buildSQLFromAST } from "./shared";
|
import { buildSQLFromAST } from "./shared";
|
||||||
|
|
||||||
export const affinity = new Proxy(
|
const affinity = {
|
||||||
|
[DB.MYSQL]: new Proxy(
|
||||||
{ INT: "INTEGER" },
|
{ INT: "INTEGER" },
|
||||||
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
|
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
|
||||||
);
|
),
|
||||||
|
[DB.GENERIC]: new Proxy(
|
||||||
|
{
|
||||||
|
INT: "INTEGER",
|
||||||
|
TINYINT: "SMALLINT",
|
||||||
|
MEDIUMINT: "INTEGER",
|
||||||
|
BIT: "BOOLEAN",
|
||||||
|
YEAR: "INTEGER",
|
||||||
|
},
|
||||||
|
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
export function fromMySQL(ast, diagramDb = DB.GENERIC) {
|
export function fromMySQL(ast, diagramDb = DB.GENERIC) {
|
||||||
const tables = [];
|
const tables = [];
|
||||||
@@ -28,7 +40,7 @@ export function fromMySQL(ast, diagramDb = DB.GENERIC) {
|
|||||||
|
|
||||||
let type = d.definition.dataType;
|
let type = d.definition.dataType;
|
||||||
if (!dbToTypes[diagramDb][type]) {
|
if (!dbToTypes[diagramDb][type]) {
|
||||||
type = affinity[type];
|
type = affinity[diagramDb][type];
|
||||||
}
|
}
|
||||||
field.type = type;
|
field.type = type;
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { Cardinality, DB } from "../../data/constants";
|
|||||||
import { dbToTypes } from "../../data/datatypes";
|
import { dbToTypes } from "../../data/datatypes";
|
||||||
import { buildSQLFromAST } from "./shared";
|
import { buildSQLFromAST } from "./shared";
|
||||||
|
|
||||||
export const affinity = new Proxy(
|
const affinity = {
|
||||||
|
[DB.SQLITE]: new Proxy(
|
||||||
{
|
{
|
||||||
INT: "INTEGER",
|
INT: "INTEGER",
|
||||||
TINYINT: "INTEGER",
|
TINYINT: "INTEGER",
|
||||||
@@ -18,10 +19,22 @@ export const affinity = new Proxy(
|
|||||||
DOUBLE: "REAL",
|
DOUBLE: "REAL",
|
||||||
FLOAT: "REAL",
|
FLOAT: "REAL",
|
||||||
},
|
},
|
||||||
|
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
|
||||||
|
),
|
||||||
|
[DB.GENERIC]: new Proxy(
|
||||||
{
|
{
|
||||||
get: (target, prop) => (prop in target ? target[prop] : "BLOB"),
|
INT: "INTEGER",
|
||||||
|
TINYINT: "SMALLINT",
|
||||||
|
MEDIUMINT: "INTEGER",
|
||||||
|
INT2: "INTEGER",
|
||||||
|
INT8: "INTEGER",
|
||||||
|
CHARACTER: "TEXT",
|
||||||
|
NCHARACTER: "TEXT",
|
||||||
|
NVARCHAR: "VARCHAR",
|
||||||
},
|
},
|
||||||
);
|
{ get: (target, prop) => (prop in target ? target[prop] : "BLOB") },
|
||||||
|
),
|
||||||
|
};
|
||||||
|
|
||||||
export function fromSQLite(ast, diagramDb = DB.GENERIC) {
|
export function fromSQLite(ast, diagramDb = DB.GENERIC) {
|
||||||
console.log(ast);
|
console.log(ast);
|
||||||
@@ -45,7 +58,7 @@ export function fromSQLite(ast, diagramDb = DB.GENERIC) {
|
|||||||
|
|
||||||
let type = d.definition.dataType;
|
let type = d.definition.dataType;
|
||||||
if (!dbToTypes[diagramDb][type]) {
|
if (!dbToTypes[diagramDb][type]) {
|
||||||
type = affinity[type];
|
type = affinity[diagramDb][type];
|
||||||
}
|
}
|
||||||
field.type = type;
|
field.type = type;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user