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

Data typed fixed #2

Closed
wants to merge 9 commits 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
26 changes: 0 additions & 26 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@uiw/codemirror-theme-github": "^4.21.25",
"@uiw/codemirror-theme-vscode": "^4.21.25",
"@uiw/react-codemirror": "^4.21.25",
"@vercel/analytics": "^1.2.2",
"axios": "^1.7.4",
"classnames": "^2.5.1",
"dexie": "^3.2.4",
Expand Down
Binary file added src/assets/oracle-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions src/components/EditorHeader/ControlPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
jsonToSQLite,
jsonToMariaDB,
jsonToSQLServer,
jsonToOracle,
} from "../../utils/exportSQL/generic";
import {
ObjectType,
Expand Down Expand Up @@ -827,6 +828,12 @@ export default function ControlPanel({
setImportDb(DB.MSSQL);
},
},
{
Oracle: () => {
setModal(MODAL.IMPORT_SRC);
setImportDb(DB.ORACLE);
},
},
],
}),
function: () => {
Expand Down Expand Up @@ -918,6 +925,22 @@ export default function ControlPanel({
}));
},
},
{
Oracle: () => {
setModal(MODAL.CODE);
const src = jsonToOracle({
tables: tables,
references: relationships,
types: types,
database: database,
});
setExportData((prev) => ({
...prev,
data: src,
extension: "sql",
}));
}
},
],
}),
function: () => {
Expand Down
1 change: 1 addition & 0 deletions src/data/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,6 @@ export const DB = {
MSSQL: "transactsql",
SQLITE: "sqlite",
MARIADB: "mariadb",
ORACLE: "oracledb",
GENERIC: "generic",
};
7 changes: 7 additions & 0 deletions src/data/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import postgresImage from "../assets/postgres-icon.png";
import sqliteImage from "../assets/sqlite-icon.png";
import mariadbImage from "../assets/mariadb-icon.png";
import mssqlImage from "../assets/mssql-icon.png";
import oracleImage from "../assets/oracle-icon.png";
import i18n from "../i18n/i18n";
import { DB } from "./constants";

Expand Down Expand Up @@ -42,6 +43,12 @@ export const databases = new Proxy(
image: mssqlImage,
hasTypes: false,
},
[DB.ORACLE]: {
name: "Oracle",
label: DB.ORACLE,
image: oracleImage,
hasTypes: true,
},
[DB.GENERIC]: {
name: i18n.t("generic"),
label: DB.GENERIC,
Expand Down
197 changes: 195 additions & 2 deletions src/data/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ const binaryRegex = /^[01]+$/;

/* eslint-disable no-unused-vars */
const defaultTypesBase = {
NUMBER: {
type: "NUMBER",
checkDefault: (field) => {
return intRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
canIncrement: true,
},
INT: {
type: "INT",
checkDefault: (field) => {
Expand Down Expand Up @@ -263,12 +273,193 @@ const defaultTypesBase = {
hasPrecision: false,
noDefault: true,
},
VARCHAR2: {
type: "VARCHAR2",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 10,
},
};

export const defaultTypes = new Proxy(defaultTypesBase, {
get: (target, prop) => (prop in target ? target[prop] : false),
});

const oracleTypesBase = {
VARCHAR2: {
type: "VARCHAR2",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 255,
hasQuotes: true,
},
NUMBER: {
type: "NUMBER",
checkDefault: (field) => {
return intRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
canIncrement: true,
},
FLOAT: {
type: "FLOAT",
checkDefault: (field) => {
return doubleRegex.test(field.default);
},
hasCheck: true,
isSized: false,
hasPrecision: true,
},
CHAR: {
type: "CHAR",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 1,
hasQuotes: true,
},
VARCHAR: {
type: "VARCHAR",
checkDefault: (field) => {
if (strHasQuotes(field.default)) {
return field.default.length - 2 <= field.size;
}
return field.default.length <= field.size;
},
hasCheck: true,
isSized: true,
hasPrecision: false,
defaultSize: 255,
hasQuotes: true,
},
TEXT: {
type: "TEXT",
checkDefault: (field) => true,
hasCheck: false,
isSized: true,
hasPrecision: false,
defaultSize: 65535,
hasQuotes: true,
},
TIME: {
type: "TIME",
checkDefault: (field) => {
return /^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d$/.test(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
TIMESTAMP: {
type: "TIMESTAMP",
checkDefault: (field) => {
if (field.default.toUpperCase() === "CURRENT_TIMESTAMP") {
return true;
}
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default)) {
return false;
}
const content = field.default.split(" ");
const date = content[0].split("-");
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
DATE: {
type: "DATE",
checkDefault: (field) => {
return /^\d{4}-\d{2}-\d{2}$/.test(field.default);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
DATETIME: {
type: "DATETIME",
checkDefault: (field) => {
if (field.default.toUpperCase() === "CURRENT_TIMESTAMP") {
return true;
}
if (!/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default)) {
return false;
}
const c = field.default.split(" ");
const d = c[0].split("-");
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
},
hasCheck: false,
isSized: false,
hasPrecision: false,
hasQuotes: true,
},
BOOLEAN: {
type: "BOOLEAN",
checkDefault: (field) => {
return (
field.default.toLowerCase() === "false" ||
field.default.toLowerCase() === "true" ||
field.default === "0" ||
field.default === "1"
);
},
hasCheck: false,
isSized: false,
hasPrecision: false,
},
BINARY: {
type: "BINARY",
checkDefault: (field) => {
return (
field.default.length <= field.size && binaryRegex.test(field.default)
);
},
hasCheck: false,
isSized: true,
hasPrecision: false,
defaultSize: 1,
hasQuotes: true,
},
BLOB: {
type: "BLOB",
checkDefault: (field) => true,
isSized: false,
hasCheck: false,
hasPrecision: false,
noDefault: true,
},
};

export const oracleTypes = new Proxy(oracleTypesBase, {
get: (target, prop) => (prop in target ? target[prop] : false),
});

const mysqlTypesBase = {
TINYINT: {
type: "TINYINT",
Expand Down Expand Up @@ -913,8 +1104,9 @@ const postgresTypesBase = {
checkDefault: (field) => {
const specialValues = ["now", "allballs"];
return (
/^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d([+-]\d{2}:\d{2})?$/.test(field.default) ||
specialValues.includes(field.default.toLowerCase())
/^(?:[01]?\d|2[0-3]):[0-5]?\d:[0-5]?\d([+-]\d{2}:\d{2})?$/.test(
field.default,
) || specialValues.includes(field.default.toLowerCase())
);
},
hasCheck: false,
Expand Down Expand Up @@ -1698,6 +1890,7 @@ const dbToTypesBase = {
[DB.SQLITE]: sqliteTypes,
[DB.MSSQL]: mssqlTypes,
[DB.MARIADB]: mysqlTypes,
[DB.ORACLE]: oracleTypes,
};

export const dbToTypes = new Proxy(dbToTypesBase, {
Expand Down
2 changes: 0 additions & 2 deletions src/main.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import ReactDOM from "react-dom/client";
import { LocaleProvider } from "@douyinfe/semi-ui";
import { Analytics } from "@vercel/analytics/react";
import App from "./App.jsx";
import en_US from "@douyinfe/semi-ui/lib/es/locale/source/en_US";
import "./index.css";
Expand All @@ -10,6 +9,5 @@ const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(
<LocaleProvider locale={en_US}>
<App />
<Analytics />
</LocaleProvider>,
);
Loading
Loading