Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom column type #106

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions src/components/EditorSidePanel/TablesTab/FieldDetails.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,22 @@ export default function FieldDetails({ data, tid, index }) {
setRedoStack([]);
}}
/>
{(data.type === "ENUM" || data.type === "SET") && (
{(data.type === "ENUM" || data.type === "SET" || data.type === "CUSTOM") && (
<>
<div className="font-semibold mb-1">{data.type} values</div>
<TagInput
separator={[",", ", ", " ,"]}
separator={
data.type === "CUSTOM" ? [] : [",", ", ", " ,"]
}
value={data.values}
validateStatus={
!data.values || data.values.length === 0 ? "error" : "default"
}
addOnBlur
className="my-2"
placeholder="Use ',' for batch input"
placeholder={
data.type === "CUSTOM" ? "Enter a custom value" : "Use ',' for batch input"
}
onChange={(v) => updateField(tid, index, { values: v })}
onFocus={() => setEditField({ values: data.values })}
onBlur={() => {
Expand Down
10 changes: 7 additions & 3 deletions src/components/EditorSidePanel/TypesTab/TypeField.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,23 @@ export default function TypeField({ data, tid, fid }) {
<Popover
content={
<div className="popover-theme w-[240px]">
{(data.type === "ENUM" || data.type === "SET") && (
{(data.type === "ENUM" || data.type === "SET" || data.type === "CUSTOM") && (
<>
<div className="font-semibold mb-1">{data.type} values</div>
<TagInput
separator={[",", ", ", " ,"]}
separator={
data.type === "CUSTOM" ? [] : [",", ", ", " ,"]
}
value={data.values}
validateStatus={
!data.values || data.values.length === 0
? "error"
: "default"
}
className="my-2"
placeholder="Use ',' for batch input"
placeholder={
data.type === "CUSTOM" ? "Enter a custom value" : "Use ',' for batch input"
}
onChange={(v) =>
updateType(tid, {
fields: types[tid].fields.map((e, id) =>
Expand Down
1 change: 1 addition & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const sqlDataTypes = [
"UUID",
"ENUM",
"SET",
"CUSTOM"
];

export const tableThemes = [
Expand Down
10 changes: 10 additions & 0 deletions src/utils/toSQL.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export function getTypeString(field, dbms = "mysql", baseType = false) {
if (field.type === "SET" || field.type === "ENUM") {
return `${field.type}(${field.values.map((v) => `"${v}"`).join(", ")})`;
}
if (field.type === "CUSTOM") {
return `${field.values}`;
}
if (!sqlDataTypes.includes(field.type)) {
return "JSON";
}
Expand All @@ -67,6 +70,9 @@ export function getTypeString(field, dbms = "mysql", baseType = false) {
if (field.type === "ENUM") {
return `${field.name}_t`;
}
if (field.type === "CUSTOM") {
return `${field.values}`;
}
if (field.type === "SET") {
return `${field.name}_t[]`;
}
Expand Down Expand Up @@ -98,6 +104,8 @@ export function getTypeString(field, dbms = "mysql", baseType = false) {
: `NVARCHAR(255) CHECK([${field.name}] in (${field.values
.map((v) => `'${v}'`)
.join(", ")}))`;
case "CUSTOM":
return field.values;
case "VARCHAR":
type = `NVARCHAR`;
break;
Expand Down Expand Up @@ -333,6 +341,8 @@ export function getSQLiteType(field) {
return `TEXT CHECK("${field.name}" in (${field.values
.map((v) => `'${v}'`)
.join(", ")}))`;
case "CUSTOM":
return field.values;
default:
return "BLOB";
}
Expand Down