diff --git a/src/components/table.jsx b/src/components/table.jsx index 4145293..f511337 100644 --- a/src/components/table.jsx +++ b/src/components/table.jsx @@ -348,17 +348,11 @@ export default function Table(props) { (value === "INT" || value === "BIGINT" || value === "SMALLINT"); - updateField( - props.tableData.id, - j, - value === "ENUM" - ? { type: value, enumValues: [], increment: incr } - : { - type: value, - length: value === "VARCHAR" ? 255 : "n/a", - increment: incr, - } - ); + updateField(props.tableData.id, j, { + type: value, + length: value === "VARCHAR" ? 255 : "n/a", + increment: incr, + }); }} > @@ -450,26 +444,26 @@ export default function Table(props) { setRedoStack([]); }} /> - {f.type === "ENUM" && ( + {(f.type === "ENUM" || f.type === "SET") && ( <> -
Enum values
+
+ {f.type} values +
updateField(props.tableData.id, j, { - enumValues: v, + values: v, }) } - onFocus={(e) => - setEditField({ enumValues: f.enumValues }) - } + onFocus={(e) => setEditField({ values: f.values })} onBlur={(e) => { if ( - JSON.stringify(editField.enumValues) === - JSON.stringify(f.enumValues) + JSON.stringify(editField.values) === + JSON.stringify(f.values) ) return; setUndoStack((prev) => [ @@ -481,7 +475,7 @@ export default function Table(props) { tid: props.tableData.id, fid: j, undo: editField, - redo: { enumValues: f.enumValues }, + redo: { values: f.values }, }, ]); setRedoStack([]); diff --git a/src/components/table_overview.jsx b/src/components/table_overview.jsx index 9710a4b..31c3f07 100644 --- a/src/components/table_overview.jsx +++ b/src/components/table_overview.jsx @@ -183,17 +183,11 @@ export default function TableOverview(props) { (value === "INT" || value === "BIGINT" || value === "SMALLINT"); - updateField( - i, - j, - value === "ENUM" - ? { type: value, enumValues: [], increment: incr } - : { - type: value, - length: value === "VARCHAR" ? 255 : "n/a", - increment: incr, - } - ); + updateField(i, j, { + type: value, + length: value === "VARCHAR" ? 255 : "n/a", + increment: incr, + }); }} > @@ -286,26 +280,26 @@ export default function TableOverview(props) { setRedoStack([]); }} /> - {f.type === "ENUM" && ( + {(f.type === "ENUM" || f.type === "SET") && ( <>
- Enum values + {f.type} values
- updateField(i, j, { enumValues: v }) + updateField(i, j, { values: v }) } onFocus={(e) => - setEditField({ enumValues: f.enumValues }) + setEditField({ values: f.values }) } onBlur={(e) => { if ( - JSON.stringify(editField.enumValues) === - JSON.stringify(f.enumValues) + JSON.stringify(editField.values) === + JSON.stringify(f.values) ) return; setUndoStack((prev) => [ @@ -317,7 +311,7 @@ export default function TableOverview(props) { tid: i, fid: j, undo: editField, - redo: { enumValues: f.enumValues }, + redo: { values: f.values }, }, ]); setRedoStack([]); diff --git a/src/data/data.js b/src/data/data.js index 04f3bb1..86f9fac 100644 --- a/src/data/data.js +++ b/src/data/data.js @@ -20,6 +20,7 @@ const sqlDataTypes = [ "BLOB", "JSON", "ENUM", + "SET", ]; const tableThemes = [ diff --git a/src/schemas/index.js b/src/schemas/index.js index 2d0c117..46a639c 100644 --- a/src/schemas/index.js +++ b/src/schemas/index.js @@ -19,6 +19,8 @@ const tableSchema = { notNull: { type: "boolean" }, increment: { type: "boolean" }, comment: { type: "string" }, + length: { type: ["string", "number"] }, + values: { type: "array", items: { type: "string" } }, }, required: [ "name", @@ -30,6 +32,7 @@ const tableSchema = { "notNull", "increment", "comment", + "length", ], }, }, @@ -86,69 +89,7 @@ const jsonSchema = { properties: { tables: { type: "array", - items: { - 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", - ], - }, + items: { ...tableSchema }, }, relationships: { type: "array", @@ -190,35 +131,11 @@ const jsonSchema = { }, notes: { type: "array", - items: { - 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"], - }, + items: { ...noteSchema }, }, subjectAreas: { type: "array", - items: { - 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"], - }, + items: { ...areaSchema }, }, }, required: ["tables", "relationships", "notes", "subjectAreas"], diff --git a/src/utils/index.js b/src/utils/index.js index e15062a..dcc70c7 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -61,8 +61,8 @@ function jsonToSQL(obj) { }\` ${field.type}${ field.length !== "n/a" ? `(${field.length})` - : field.enumValues - ? `(${field.enumValues.map((v) => `"${v}"`).join(", ")})` + : field.type === "ENUM" || field.type === "SET" + ? `(${field.values.map((v) => `"${v}"`).join(", ")})` : "" }${field.notNull ? " NOT NULL" : ""}${ field.increment ? " AUTO_INCREMENT" : ""