diff --git a/src/data/datatypes.js b/src/data/datatypes.js index 7eb68825..5feec1ec 100644 --- a/src/data/datatypes.js +++ b/src/data/datatypes.js @@ -2201,6 +2201,77 @@ const oraclesqlTypesBase = { defaultSize: 255, hasQuotes: false, }, + INT: { + type: "NUMBER", + color: intColor, + checkDefault: (field) => intRegex.test(field.default), + hasCheck: true, + isSized: false, + hasPrecision: true, + canIncrement: false, + }, + SMALLINT: { + type: "NUMBER", + color: intColor, + checkDefault: (field) => intRegex.test(field.default), + hasCheck: true, + isSized: false, + hasPrecision: true, + canIncrement: false, + }, + BIGINT: { + type: "NUMBER", + color: intColor, + checkDefault: (field) => intRegex.test(field.default), + hasCheck: true, + isSized: false, + hasPrecision: true, + canIncrement: false, + }, + DECIMAL: { + type: "NUMBER", + color: decimalColor, + checkDefault: (field) => doubleRegex.test(field.default), + hasCheck: true, + isSized: false, + hasPrecision: true, + }, + DOUBLE: { + type: "BINARY_DOUBLE", + color: decimalColor, + checkDefault: (field) => doubleRegex.test(field.default), + hasCheck: true, + isSized: false, + hasPrecision: true, + }, + VARCHAR: { + type: "VARCHAR2", + color: stringColor, + checkDefault: (field) => field.default.length <= field.size, + hasCheck: true, + isSized: true, + hasPrecision: false, + defaultSize: 255, + hasQuotes: true, + }, + TEXT: { + type: "CLOB", + color: stringColor, + checkDefault: (field) => true, + hasCheck: false, + isSized: false, + hasPrecision: false, + hasQuotes: true, + }, + ENUM: { + type: "ENUM", + color: enumSetColor, + checkDefault: (field) => field.values.includes(field.default), + hasCheck: false, + isSized: false, + hasPrecision: false, + hasQuotes: true, + }, }; export const oraclesqlTypes = new Proxy(oraclesqlTypesBase, { diff --git a/src/utils/exportSQL/oraclesql.js b/src/utils/exportSQL/oraclesql.js index 0a44c565..a7288f4c 100644 --- a/src/utils/exportSQL/oraclesql.js +++ b/src/utils/exportSQL/oraclesql.js @@ -4,31 +4,25 @@ import { parseDefault } from "./shared"; export function toOracleSQL(diagram) { return `${diagram.tables .map( - (table) => + (table) => `${ table.comment === "" ? "" : `/* ${table.comment} */\n` }CREATE TABLE "${table.name}" (\n${table.fields - .map( - (field) => - `${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t"${ - field.name - }" ${field.type}${ - field.size !== undefined && field.size !== "" - ? "(" + field.size + ")" - : "" - }${field.notNull ? " NOT NULL" : ""}${ - field.increment ? " GENERATED ALWAYS AS IDENTITY" : "" - }${field.unique ? " UNIQUE" : ""}${ - field.default !== "" - ? ` DEFAULT ${parseDefault(field, diagram.database)}` - : "" - }${ - field.check === "" || - !dbToTypes[diagram.database][field.type].hasCheck - ? "" - : ` CHECK(${field.check})` - }${field.comment ? ` -- ${field.comment}` : ""}`, - ) + .map((field) => { + const typeInfo = dbToTypes[diagram.database][field.type] || { type: field.type }; + const oracleType = typeInfo.type; + return `${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t"${ + field.name + }" ${oracleType}${ + typeInfo.isSized && field.size ? `(${field.size})` : "" + }${field.notNull ? " NOT NULL" : ""}${field.increment ? " GENERATED ALWAYS AS IDENTITY" : ""}${field.unique ? " UNIQUE" : ""}${ + field.default !== "" ? ` DEFAULT ${parseDefault(field, diagram.database)}` : "" + }${ + field.check === "" || !typeInfo.hasCheck + ? "" + : ` CHECK(${field.check})` + }${field.comment ? ` -- ${field.comment}` : ""}`; + }) .join(",\n")}${ table.fields.filter((f) => f.primary).length > 0 ? `,\n\tPRIMARY KEY(${table.fields @@ -57,7 +51,7 @@ export function toOracleSQL(diagram) { startFields.find((f) => f.id === r.startFieldId).name }") REFERENCES "${endName}" ("${ endFields.find((f) => f.id === r.endFieldId).name - }")\nON UPDATE ${r.updateConstraint.toUpperCase()} ON DELETE ${r.deleteConstraint.toUpperCase()};`; + }")\nON DELETE ${r.deleteConstraint.toUpperCase()};`; }) .join("\n")}`; }