add sets
This commit is contained in:
parent
662e2294e8
commit
2760f458af
@ -348,17 +348,11 @@ export default function Table(props) {
|
|||||||
(value === "INT" ||
|
(value === "INT" ||
|
||||||
value === "BIGINT" ||
|
value === "BIGINT" ||
|
||||||
value === "SMALLINT");
|
value === "SMALLINT");
|
||||||
updateField(
|
updateField(props.tableData.id, j, {
|
||||||
props.tableData.id,
|
type: value,
|
||||||
j,
|
length: value === "VARCHAR" ? 255 : "n/a",
|
||||||
value === "ENUM"
|
increment: incr,
|
||||||
? { type: value, enumValues: [], increment: incr }
|
});
|
||||||
: {
|
|
||||||
type: value,
|
|
||||||
length: value === "VARCHAR" ? 255 : "n/a",
|
|
||||||
increment: incr,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
></Select>
|
></Select>
|
||||||
</Col>
|
</Col>
|
||||||
@ -450,26 +444,26 @@ export default function Table(props) {
|
|||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{f.type === "ENUM" && (
|
{(f.type === "ENUM" || f.type === "SET") && (
|
||||||
<>
|
<>
|
||||||
<div className="font-semibold mb-1">Enum values</div>
|
<div className="font-semibold mb-1">
|
||||||
|
{f.type} values
|
||||||
|
</div>
|
||||||
<TagInput
|
<TagInput
|
||||||
separator={[",", ", ", " ,"]}
|
separator={[",", ", ", " ,"]}
|
||||||
value={f.enumValues}
|
value={f.values}
|
||||||
className="my-2"
|
className="my-2"
|
||||||
placeholder="Use ',' for batch input"
|
placeholder="Use ',' for batch input"
|
||||||
onChange={(v) =>
|
onChange={(v) =>
|
||||||
updateField(props.tableData.id, j, {
|
updateField(props.tableData.id, j, {
|
||||||
enumValues: v,
|
values: v,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
onFocus={(e) =>
|
onFocus={(e) => setEditField({ values: f.values })}
|
||||||
setEditField({ enumValues: f.enumValues })
|
|
||||||
}
|
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (
|
if (
|
||||||
JSON.stringify(editField.enumValues) ===
|
JSON.stringify(editField.values) ===
|
||||||
JSON.stringify(f.enumValues)
|
JSON.stringify(f.values)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
setUndoStack((prev) => [
|
setUndoStack((prev) => [
|
||||||
@ -481,7 +475,7 @@ export default function Table(props) {
|
|||||||
tid: props.tableData.id,
|
tid: props.tableData.id,
|
||||||
fid: j,
|
fid: j,
|
||||||
undo: editField,
|
undo: editField,
|
||||||
redo: { enumValues: f.enumValues },
|
redo: { values: f.values },
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
|
@ -183,17 +183,11 @@ export default function TableOverview(props) {
|
|||||||
(value === "INT" ||
|
(value === "INT" ||
|
||||||
value === "BIGINT" ||
|
value === "BIGINT" ||
|
||||||
value === "SMALLINT");
|
value === "SMALLINT");
|
||||||
updateField(
|
updateField(i, j, {
|
||||||
i,
|
type: value,
|
||||||
j,
|
length: value === "VARCHAR" ? 255 : "n/a",
|
||||||
value === "ENUM"
|
increment: incr,
|
||||||
? { type: value, enumValues: [], increment: incr }
|
});
|
||||||
: {
|
|
||||||
type: value,
|
|
||||||
length: value === "VARCHAR" ? 255 : "n/a",
|
|
||||||
increment: incr,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}}
|
}}
|
||||||
></Select>
|
></Select>
|
||||||
</Col>
|
</Col>
|
||||||
@ -286,26 +280,26 @@ export default function TableOverview(props) {
|
|||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{f.type === "ENUM" && (
|
{(f.type === "ENUM" || f.type === "SET") && (
|
||||||
<>
|
<>
|
||||||
<div className="font-semibold mb-1">
|
<div className="font-semibold mb-1">
|
||||||
Enum values
|
{f.type} values
|
||||||
</div>
|
</div>
|
||||||
<TagInput
|
<TagInput
|
||||||
separator={[",", ", ", " ,"]}
|
separator={[",", ", ", " ,"]}
|
||||||
value={f.enumValues}
|
value={f.values}
|
||||||
className="my-2"
|
className="my-2"
|
||||||
placeholder="Use ',' for batch input"
|
placeholder="Use ',' for batch input"
|
||||||
onChange={(v) =>
|
onChange={(v) =>
|
||||||
updateField(i, j, { enumValues: v })
|
updateField(i, j, { values: v })
|
||||||
}
|
}
|
||||||
onFocus={(e) =>
|
onFocus={(e) =>
|
||||||
setEditField({ enumValues: f.enumValues })
|
setEditField({ values: f.values })
|
||||||
}
|
}
|
||||||
onBlur={(e) => {
|
onBlur={(e) => {
|
||||||
if (
|
if (
|
||||||
JSON.stringify(editField.enumValues) ===
|
JSON.stringify(editField.values) ===
|
||||||
JSON.stringify(f.enumValues)
|
JSON.stringify(f.values)
|
||||||
)
|
)
|
||||||
return;
|
return;
|
||||||
setUndoStack((prev) => [
|
setUndoStack((prev) => [
|
||||||
@ -317,7 +311,7 @@ export default function TableOverview(props) {
|
|||||||
tid: i,
|
tid: i,
|
||||||
fid: j,
|
fid: j,
|
||||||
undo: editField,
|
undo: editField,
|
||||||
redo: { enumValues: f.enumValues },
|
redo: { values: f.values },
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
setRedoStack([]);
|
setRedoStack([]);
|
||||||
|
@ -20,6 +20,7 @@ const sqlDataTypes = [
|
|||||||
"BLOB",
|
"BLOB",
|
||||||
"JSON",
|
"JSON",
|
||||||
"ENUM",
|
"ENUM",
|
||||||
|
"SET",
|
||||||
];
|
];
|
||||||
|
|
||||||
const tableThemes = [
|
const tableThemes = [
|
||||||
|
@ -19,6 +19,8 @@ const tableSchema = {
|
|||||||
notNull: { type: "boolean" },
|
notNull: { type: "boolean" },
|
||||||
increment: { type: "boolean" },
|
increment: { type: "boolean" },
|
||||||
comment: { type: "string" },
|
comment: { type: "string" },
|
||||||
|
length: { type: ["string", "number"] },
|
||||||
|
values: { type: "array", items: { type: "string" } },
|
||||||
},
|
},
|
||||||
required: [
|
required: [
|
||||||
"name",
|
"name",
|
||||||
@ -30,6 +32,7 @@ const tableSchema = {
|
|||||||
"notNull",
|
"notNull",
|
||||||
"increment",
|
"increment",
|
||||||
"comment",
|
"comment",
|
||||||
|
"length",
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -86,69 +89,7 @@ const jsonSchema = {
|
|||||||
properties: {
|
properties: {
|
||||||
tables: {
|
tables: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: { ...tableSchema },
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
id: { type: "integer" },
|
|
||||||
name: { type: "string" },
|
|
||||||
x: { type: "number" },
|
|
||||||
y: { type: "number" },
|
|
||||||
fields: {
|
|
||||||
type: "array",
|
|
||||||
items: {
|
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
name: { type: "string" },
|
|
||||||
type: { type: "string" },
|
|
||||||
default: { type: "string" },
|
|
||||||
check: { type: "string" },
|
|
||||||
primary: { type: "boolean" },
|
|
||||||
unique: { type: "boolean" },
|
|
||||||
notNull: { type: "boolean" },
|
|
||||||
increment: { type: "boolean" },
|
|
||||||
comment: { type: "string" },
|
|
||||||
},
|
|
||||||
required: [
|
|
||||||
"name",
|
|
||||||
"type",
|
|
||||||
"default",
|
|
||||||
"check",
|
|
||||||
"primary",
|
|
||||||
"unique",
|
|
||||||
"notNull",
|
|
||||||
"increment",
|
|
||||||
"comment",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
comment: { type: "string" },
|
|
||||||
indices: {
|
|
||||||
type: "array",
|
|
||||||
items: {
|
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
name: { type: "string" },
|
|
||||||
fields: {
|
|
||||||
type: "array",
|
|
||||||
items: { type: "string" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
required: ["name", "fields"],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
||||||
},
|
|
||||||
required: [
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"x",
|
|
||||||
"y",
|
|
||||||
"fields",
|
|
||||||
"comment",
|
|
||||||
"indices",
|
|
||||||
"color",
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
relationships: {
|
relationships: {
|
||||||
type: "array",
|
type: "array",
|
||||||
@ -190,35 +131,11 @@ const jsonSchema = {
|
|||||||
},
|
},
|
||||||
notes: {
|
notes: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: { ...noteSchema },
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
id: { type: "integer" },
|
|
||||||
x: { type: "number" },
|
|
||||||
y: { type: "number" },
|
|
||||||
title: { type: "string" },
|
|
||||||
content: { type: "string" },
|
|
||||||
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
||||||
height: { type: "number" },
|
|
||||||
},
|
|
||||||
required: ["id", "x", "y", "title", "content", "color", "height"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
subjectAreas: {
|
subjectAreas: {
|
||||||
type: "array",
|
type: "array",
|
||||||
items: {
|
items: { ...areaSchema },
|
||||||
type: "object",
|
|
||||||
properties: {
|
|
||||||
id: { type: "integer" },
|
|
||||||
name: { type: "string" },
|
|
||||||
x: { type: "number" },
|
|
||||||
y: { type: "number" },
|
|
||||||
width: { type: "number" },
|
|
||||||
height: { type: "number" },
|
|
||||||
color: { type: "string", pattern: "^#[0-9a-fA-F]{6}$" },
|
|
||||||
},
|
|
||||||
required: ["id", "name", "x", "y", "width", "height", "color"],
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
required: ["tables", "relationships", "notes", "subjectAreas"],
|
required: ["tables", "relationships", "notes", "subjectAreas"],
|
||||||
|
@ -61,8 +61,8 @@ function jsonToSQL(obj) {
|
|||||||
}\` ${field.type}${
|
}\` ${field.type}${
|
||||||
field.length !== "n/a"
|
field.length !== "n/a"
|
||||||
? `(${field.length})`
|
? `(${field.length})`
|
||||||
: field.enumValues
|
: field.type === "ENUM" || field.type === "SET"
|
||||||
? `(${field.enumValues.map((v) => `"${v}"`).join(", ")})`
|
? `(${field.values.map((v) => `"${v}"`).join(", ")})`
|
||||||
: ""
|
: ""
|
||||||
}${field.notNull ? " NOT NULL" : ""}${
|
}${field.notNull ? " NOT NULL" : ""}${
|
||||||
field.increment ? " AUTO_INCREMENT" : ""
|
field.increment ? " AUTO_INCREMENT" : ""
|
||||||
|
Loading…
Reference in New Issue
Block a user