Skip to content

Commit 7020f6b

Browse files
authored
Merge branch 'main' into fix/oracle-export-type-mapping
2 parents aab7099 + ee542bd commit 7020f6b

File tree

3 files changed

+78
-48
lines changed

3 files changed

+78
-48
lines changed

src/components/EditorHeader/Modal/ImportSource.jsx

Lines changed: 58 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { Upload, Checkbox, Banner } from "@douyinfe/semi-ui";
1+
import { Upload, Checkbox, Banner, Tabs, TabPane } from "@douyinfe/semi-ui";
22
import { STATUS } from "../../../data/constants";
33
import { useTranslation } from "react-i18next";
4+
import CodeEditor from "../../CodeEditor";
45

56
export default function ImportSource({
67
importData,
@@ -12,45 +13,63 @@ export default function ImportSource({
1213

1314
return (
1415
<div>
15-
<Upload
16-
action="#"
17-
beforeUpload={({ file, fileList }) => {
18-
const f = fileList[0].fileInstance;
19-
if (!f) {
20-
return;
21-
}
22-
const reader = new FileReader();
23-
reader.onload = async (e) => {
24-
setImportData((prev) => ({ ...prev, src: e.target.result }));
25-
};
26-
reader.readAsText(f);
16+
<Tabs>
17+
<TabPane tab={t("insert_sql")} itemKey="text-import">
18+
<CodeEditor
19+
className="h-56"
20+
language="sql"
21+
onChange={(value) => {
22+
setImportData((prev) => ({ ...prev, src: value }));
23+
setError({
24+
type: STATUS.NONE,
25+
message: "",
26+
});
27+
}}
28+
/>
29+
</TabPane>
30+
<TabPane tab={t("upload_file")} itemKey="file-import">
31+
<Upload
32+
action="#"
33+
beforeUpload={({ file, fileList }) => {
34+
const f = fileList[0].fileInstance;
35+
if (!f) {
36+
return;
37+
}
38+
const reader = new FileReader();
39+
reader.onload = async (e) => {
40+
setImportData((prev) => ({ ...prev, src: e.target.result }));
41+
};
42+
reader.readAsText(f);
43+
44+
return {
45+
autoRemove: false,
46+
fileInstance: file.fileInstance,
47+
status: "success",
48+
shouldUpload: false,
49+
};
50+
}}
51+
draggable={true}
52+
dragMainText={t("drag_and_drop_files")}
53+
dragSubText={t("upload_sql_to_generate_diagrams")}
54+
accept=".sql"
55+
onRemove={() => {
56+
setError({
57+
type: STATUS.NONE,
58+
message: "",
59+
});
60+
setImportData((prev) => ({ ...prev, src: "" }));
61+
}}
62+
onFileChange={() =>
63+
setError({
64+
type: STATUS.NONE,
65+
message: "",
66+
})
67+
}
68+
limit={1}
69+
/>
70+
</TabPane>
71+
</Tabs>
2772

28-
return {
29-
autoRemove: false,
30-
fileInstance: file.fileInstance,
31-
status: "success",
32-
shouldUpload: false,
33-
};
34-
}}
35-
draggable={true}
36-
dragMainText={t("drag_and_drop_files")}
37-
dragSubText={t("upload_sql_to_generate_diagrams")}
38-
accept=".sql"
39-
onRemove={() => {
40-
setError({
41-
type: STATUS.NONE,
42-
message: "",
43-
});
44-
setImportData((prev) => ({ ...prev, src: "" }));
45-
}}
46-
onFileChange={() =>
47-
setError({
48-
type: STATUS.NONE,
49-
message: "",
50-
})
51-
}
52-
limit={1}
53-
/>
5473
<div className="mt-2">
5574
<Checkbox
5675
aria-label="overwrite checkbox"

src/i18n/locales/en.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,8 @@ const en = {
279279
failed_to_record_version: "Failed to record version",
280280
failed_to_load_diagram: "Failed to load diagram",
281281
see_all: "See all",
282+
insert_sql: "Insert SQL",
283+
upload_file: "Upload file",
282284
},
283285
};
284286

src/utils/exportAs/dbml.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ function columnDefault(field, database) {
4040
return `default: ${parseDefaultDbml(field, database)}`;
4141
}
4242

43-
function columnComment(field) {
44-
if (!field.comment || field.comment.trim() === "") {
45-
return "";
46-
}
47-
48-
return `note: '${escapeQuotes(field.comment)}'`;
49-
}
50-
5143
function columnSettings(field, database) {
5244
let constraints = [];
5345

@@ -98,6 +90,23 @@ function processComment(comment) {
9890
return `'${escapeQuotes(comment)}'`;
9991
}
10092

93+
function columnComment(field) {
94+
if (!field.comment || field.comment.trim() === "") {
95+
return "";
96+
}
97+
98+
return `note: ${processComment(field.comment)}`;
99+
}
100+
101+
function processType(type) {
102+
// TODO: remove after a while
103+
if (type.toUpperCase() === "TIMESTAMP WITH TIME ZONE") {
104+
return "timestamptz";
105+
}
106+
107+
return type.toLowerCase();
108+
}
109+
101110
export function toDBML(diagram) {
102111
const generateRelString = (rel) => {
103112
const { fields: startTableFields, name: startTableName } =
@@ -142,7 +151,7 @@ export function toDBML(diagram) {
142151
`\t${quoteIdentifier(field.name)} ${
143152
field.type === "ENUM" || field.type === "SET"
144153
? quoteIdentifier(`${field.name}_${field.values.join("_")}_t`)
145-
: field.type.toLowerCase()
154+
: processType(field.type)
146155
}${fieldSize(
147156
field,
148157
diagram.database,

0 commit comments

Comments
 (0)