Skip to content

Commit 16ea2ee

Browse files
Kingpin98k1ilit
andauthored
feat:Added support for exporting SQL as OracleDB SQL (#192)
* feat:Added support for exporting SQL as OracleDB SQL * Add parser * Import from sql * Add beta tag * Export from generic * Fix export * Add import affinity --------- Co-authored-by: 1ilit <[email protected]>
1 parent fcc16bb commit 16ea2ee

16 files changed

+739
-60
lines changed

package-lock.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"lexical": "^0.12.5",
3535
"node-sql-parser": "^5.3.8",
3636
"octokit": "^4.0.2",
37+
"oracle-sql-parser": "^0.1.0",
3738
"react": "^18.2.0",
3839
"react-dom": "^18.2.0",
3940
"react-hotkeys-hook": "^4.4.1",

src/assets/oraclesql-icon.png

14.8 KB
Loading

src/assets/oraclesql.png

28 KB
Loading

src/components/EditorHeader/ControlPanel.jsx

+86-27
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
InputNumber,
2121
Tooltip,
2222
Spin,
23+
Tag,
2324
Toast,
2425
Popconfirm,
2526
} from "@douyinfe/semi-ui";
@@ -30,6 +31,7 @@ import {
3031
jsonToSQLite,
3132
jsonToMariaDB,
3233
jsonToSQLServer,
34+
jsonToOracleSQL,
3335
} from "../../utils/exportSQL/generic";
3436
import {
3537
ObjectType,
@@ -793,48 +795,63 @@ export default function ControlPanel({
793795
import_from: {
794796
children: [
795797
{
796-
JSON: fileImport,
798+
function: fileImport,
799+
name: "JSON",
797800
},
798801
{
799-
DBML: () => {
802+
function: () => {
800803
setModal(MODAL.IMPORT);
801804
setImportFrom(IMPORT_FROM.DBML);
802805
},
806+
name: "DBML",
803807
},
804808
],
805809
},
806810
import_from_source: {
807811
...(database === DB.GENERIC && {
808812
children: [
809813
{
810-
MySQL: () => {
814+
function: () => {
811815
setModal(MODAL.IMPORT_SRC);
812816
setImportDb(DB.MYSQL);
813817
},
818+
name: "MySQL",
814819
},
815820
{
816-
PostgreSQL: () => {
821+
function: () => {
817822
setModal(MODAL.IMPORT_SRC);
818823
setImportDb(DB.POSTGRES);
819824
},
825+
name: "PostgreSQL",
820826
},
821827
{
822-
SQLite: () => {
828+
function: () => {
823829
setModal(MODAL.IMPORT_SRC);
824830
setImportDb(DB.SQLITE);
825831
},
832+
name: "SQLite",
826833
},
827834
{
828-
MariaDB: () => {
835+
function: () => {
829836
setModal(MODAL.IMPORT_SRC);
830837
setImportDb(DB.MARIADB);
831838
},
839+
name: "MariaDB",
832840
},
833841
{
834-
MSSQL: () => {
842+
function: () => {
835843
setModal(MODAL.IMPORT_SRC);
836844
setImportDb(DB.MSSQL);
837845
},
846+
name: "MSSQL",
847+
},
848+
{
849+
function: () => {
850+
setModal(MODAL.IMPORT_SRC);
851+
setImportDb(DB.ORACLESQL);
852+
},
853+
name: "Oracle",
854+
label: "Beta",
838855
},
839856
],
840857
}),
@@ -848,7 +865,8 @@ export default function ControlPanel({
848865
...(database === DB.GENERIC && {
849866
children: [
850867
{
851-
MySQL: () => {
868+
name: "MySQL",
869+
function: () => {
852870
setModal(MODAL.CODE);
853871
const src = jsonToMySQL({
854872
tables: tables,
@@ -864,7 +882,8 @@ export default function ControlPanel({
864882
},
865883
},
866884
{
867-
PostgreSQL: () => {
885+
name: "PostgreSQL",
886+
function: () => {
868887
setModal(MODAL.CODE);
869888
const src = jsonToPostgreSQL({
870889
tables: tables,
@@ -880,7 +899,8 @@ export default function ControlPanel({
880899
},
881900
},
882901
{
883-
SQLite: () => {
902+
name: "SQLite",
903+
function: () => {
884904
setModal(MODAL.CODE);
885905
const src = jsonToSQLite({
886906
tables: tables,
@@ -896,7 +916,8 @@ export default function ControlPanel({
896916
},
897917
},
898918
{
899-
MariaDB: () => {
919+
name: "MariaDB",
920+
function: () => {
900921
setModal(MODAL.CODE);
901922
const src = jsonToMariaDB({
902923
tables: tables,
@@ -912,7 +933,8 @@ export default function ControlPanel({
912933
},
913934
},
914935
{
915-
MSSQL: () => {
936+
name: "MSSQL",
937+
function: () => {
916938
setModal(MODAL.CODE);
917939
const src = jsonToSQLServer({
918940
tables: tables,
@@ -927,6 +949,24 @@ export default function ControlPanel({
927949
}));
928950
},
929951
},
952+
{
953+
label: "Beta",
954+
name: "Oracle",
955+
function: () => {
956+
setModal(MODAL.CODE);
957+
const src = jsonToOracleSQL({
958+
tables: tables,
959+
references: relationships,
960+
types: types,
961+
database: database,
962+
});
963+
setExportData((prev) => ({
964+
...prev,
965+
data: src,
966+
extension: "sql",
967+
}));
968+
},
969+
},
930970
],
931971
}),
932972
function: () => {
@@ -949,7 +989,8 @@ export default function ControlPanel({
949989
export_as: {
950990
children: [
951991
{
952-
PNG: () => {
992+
name: "PNG",
993+
function: () => {
953994
toPng(document.getElementById("canvas")).then(function (dataUrl) {
954995
setExportData((prev) => ({
955996
...prev,
@@ -961,7 +1002,8 @@ export default function ControlPanel({
9611002
},
9621003
},
9631004
{
964-
JPEG: () => {
1005+
name: "JPEG",
1006+
function: () => {
9651007
toJpeg(document.getElementById("canvas"), { quality: 0.95 }).then(
9661008
function (dataUrl) {
9671009
setExportData((prev) => ({
@@ -975,7 +1017,8 @@ export default function ControlPanel({
9751017
},
9761018
},
9771019
{
978-
SVG: () => {
1020+
name: "SVG",
1021+
function: () => {
9791022
const filter = (node) => node.tagName !== "i";
9801023
toSvg(document.getElementById("canvas"), { filter: filter }).then(
9811024
function (dataUrl) {
@@ -990,7 +1033,8 @@ export default function ControlPanel({
9901033
},
9911034
},
9921035
{
993-
JSON: () => {
1036+
name: "JSON",
1037+
function: () => {
9941038
setModal(MODAL.CODE);
9951039
const result = JSON.stringify(
9961040
{
@@ -1014,7 +1058,8 @@ export default function ControlPanel({
10141058
},
10151059
},
10161060
{
1017-
DBML: () => {
1061+
name: "DBML",
1062+
function: () => {
10181063
setModal(MODAL.CODE);
10191064
const result = toDBML({
10201065
tables,
@@ -1029,7 +1074,8 @@ export default function ControlPanel({
10291074
},
10301075
},
10311076
{
1032-
PDF: () => {
1077+
name: "PDF",
1078+
function: () => {
10331079
const canvas = document.getElementById("canvas");
10341080
toJpeg(canvas).then(function (dataUrl) {
10351081
const doc = new jsPDF("l", "px", [
@@ -1049,7 +1095,8 @@ export default function ControlPanel({
10491095
},
10501096
},
10511097
{
1052-
MERMAID: () => {
1098+
name: "Mermaid",
1099+
function: () => {
10531100
setModal(MODAL.CODE);
10541101
const result = jsonToMermaid({
10551102
tables: tables,
@@ -1067,7 +1114,8 @@ export default function ControlPanel({
10671114
},
10681115
},
10691116
{
1070-
readme: () => {
1117+
name: "Markdown",
1118+
function: () => {
10711119
setModal(MODAL.CODE);
10721120
const result = jsonToDocumentation({
10731121
tables: tables,
@@ -1271,7 +1319,8 @@ export default function ControlPanel({
12711319
theme: {
12721320
children: [
12731321
{
1274-
light: () => {
1322+
name: t("light"),
1323+
function: () => {
12751324
const body = document.body;
12761325
if (body.hasAttribute("theme-mode")) {
12771326
body.setAttribute("theme-mode", "light");
@@ -1281,7 +1330,8 @@ export default function ControlPanel({
12811330
},
12821331
},
12831332
{
1284-
dark: () => {
1333+
name: t("dark"),
1334+
function: () => {
12851335
const body = document.body;
12861336
if (body.hasAttribute("theme-mode")) {
12871337
body.setAttribute("theme-mode", "dark");
@@ -1602,9 +1652,9 @@ export default function ControlPanel({
16021652
const body = document.body;
16031653
if (body.hasAttribute("theme-mode")) {
16041654
if (body.getAttribute("theme-mode") === "light") {
1605-
menu["view"]["theme"].children[1]["dark"]();
1655+
menu["view"]["theme"].children[1].function();
16061656
} else {
1607-
menu["view"]["theme"].children[0]["light"]();
1657+
menu["view"]["theme"].children[0].function();
16081658
}
16091659
}
16101660
}}
@@ -1703,7 +1753,7 @@ export default function ControlPanel({
17031753
if (menu[category][item].children) {
17041754
return (
17051755
<Dropdown
1706-
style={{ width: "120px" }}
1756+
style={{ width: "150px" }}
17071757
key={item}
17081758
position="rightTop"
17091759
render={
@@ -1712,9 +1762,18 @@ export default function ControlPanel({
17121762
(e, i) => (
17131763
<Dropdown.Item
17141764
key={i}
1715-
onClick={Object.values(e)[0]}
1765+
onClick={e.function}
1766+
className="flex justify-between"
17161767
>
1717-
{t(Object.keys(e)[0])}
1768+
<span>{e.name}</span>
1769+
{e.label && (
1770+
<Tag
1771+
size="small"
1772+
color="light-blue"
1773+
>
1774+
{e.label}
1775+
</Tag>
1776+
)}
17181777
</Dropdown.Item>
17191778
),
17201779
)}

src/components/EditorHeader/Modal/Modal.jsx

+14-4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from "../../../hooks";
2121
import { saveAs } from "file-saver";
2222
import { Parser } from "node-sql-parser";
23+
import { Parser as OracleParser } from "oracle-sql-parser";
2324
import {
2425
getModalTitle,
2526
getModalWidth,
@@ -131,12 +132,21 @@ export default function Modal({
131132
};
132133

133134
const parseSQLAndLoadDiagram = () => {
134-
const parser = new Parser();
135+
const targetDatabase = database === DB.GENERIC ? importDb : database;
136+
135137
let ast = null;
136138
try {
137-
ast = parser.astify(importSource.src, {
138-
database: database === DB.GENERIC ? importDb : database,
139-
});
139+
if (targetDatabase === DB.ORACLESQL) {
140+
const oracleParser = new OracleParser();
141+
142+
ast = oracleParser.parse(importSource.src);
143+
} else {
144+
const parser = new Parser();
145+
146+
ast = parser.astify(importSource.src, {
147+
database: targetDatabase,
148+
});
149+
}
140150
} catch (error) {
141151
const message = error.location
142152
? `${error.name} [Ln ${error.location.start.line}, Col ${error.location.start.column}]: ${error.message}`

0 commit comments

Comments
 (0)