diff --git a/src/components/table.jsx b/src/components/table.jsx
index 293bd19..347b1d5 100644
--- a/src/components/table.jsx
+++ b/src/components/table.jsx
@@ -41,7 +41,7 @@ import {
TableContext,
UndoRedoContext,
} from "../pages/editor";
-import { getSize, hasPrecision, isSized } from "../utils";
+import { getSize, hasCheck, hasPrecision, isSized } from "../utils";
export default function Table(props) {
const [isHovered, setIsHovered] = useState(false);
@@ -405,6 +405,12 @@ export default function Table(props) {
size: "",
values: [],
});
+ } else if (hasCheck(value)) {
+ updateField(props.tableData.id, j, {
+ type: value,
+ check: "",
+ increment: incr,
+ });
} else {
updateField(props.tableData.id, j, {
type: value,
@@ -633,34 +639,45 @@ export default function Table(props) {
/>
>
)}
-
+ *This will be in the script as is.
+
+ >
+ )}
Unique
diff --git a/src/components/table_overview.jsx b/src/components/table_overview.jsx
index c204b43..08ee4e8 100644
--- a/src/components/table_overview.jsx
+++ b/src/components/table_overview.jsx
@@ -36,7 +36,7 @@ import {
IllustrationNoContentDark,
} from "@douyinfe/semi-illustrations";
import { SelectContext, TableContext, UndoRedoContext } from "../pages/editor";
-import { getSize, hasPrecision, isSized } from "../utils";
+import { getSize, hasCheck, hasPrecision, isSized } from "../utils";
export default function TableOverview(props) {
const [indexActiveKey, setIndexActiveKey] = useState("");
@@ -251,6 +251,12 @@ export default function TableOverview(props) {
size: "",
values: [],
});
+ } else if (hasCheck(value)) {
+ updateField(i, j, {
+ type: value,
+ check: "",
+ increment: incr,
+ });
} else {
updateField(i, j, {
type: value,
@@ -478,38 +484,46 @@ export default function TableOverview(props) {
/>
>
)}
-
- Check Expression
-
-
- updateField(i, j, { check: value })
- }
- onFocus={(e) =>
- setEditField({ check: e.target.value })
- }
- onBlur={(e) => {
- if (e.target.value === editField.check) return;
- setUndoStack((prev) => [
- ...prev,
- {
- action: Action.EDIT,
- element: ObjectType.TABLE,
- component: "field",
- tid: i,
- fid: j,
- undo: editField,
- redo: { check: e.target.value },
- message: `Edit table field check expression to ${e.target.value}`,
- },
- ]);
- setRedoStack([]);
- }}
- />
+ {hasCheck(f.type) && (
+ <>
+
+ Check Expression
+
+
+ updateField(i, j, { check: value })
+ }
+ onFocus={(e) =>
+ setEditField({ check: e.target.value })
+ }
+ onBlur={(e) => {
+ if (e.target.value === editField.check)
+ return;
+ setUndoStack((prev) => [
+ ...prev,
+ {
+ action: Action.EDIT,
+ element: ObjectType.TABLE,
+ component: "field",
+ tid: i,
+ fid: j,
+ undo: editField,
+ redo: { check: e.target.value },
+ message: `Edit table field check expression to ${e.target.value}`,
+ },
+ ]);
+ setRedoStack([]);
+ }}
+ />
+
+ *This will be in the script as is.
+
+ >
+ )}
Unique
diff --git a/src/utils/index.js b/src/utils/index.js
index 6f5a7d3..eb35dfb 100644
--- a/src/utils/index.js
+++ b/src/utils/index.js
@@ -99,7 +99,11 @@ function jsonToSQL(obj) {
: `${field.default}`
}`
: ""
- }${field.check === "" ? "" : ` CHECK (${field.check})`}`
+ }${
+ field.check === "" || !hasCheck(field.type)
+ ? ""
+ : ` CHECK(${field.check})`
+ }`
)
.join(",\n")}${
table.fields.filter((f) => f.primary).length > 0
@@ -149,6 +153,21 @@ function hasPrecision(type) {
return ["DOUBLE", "NUMERIC", "DECIMAL"].includes(type);
}
+function hasCheck(type) {
+ return [
+ "INT",
+ "SMALLINT",
+ "BIGINT",
+ "CHAR",
+ "VARCHAR",
+ "FLOAT",
+ "DECIMAL",
+ "DOUBLE",
+ "NUMERIC",
+ "REAL",
+ ].includes(type);
+}
+
function getSize(type) {
switch (type) {
case "CHAR":
@@ -371,4 +390,5 @@ export {
getSize,
hasPrecision,
validateDateStr,
+ hasCheck,
};