diff --git a/src/utils/exportSQL/generic.js b/src/utils/exportSQL/generic.js index 16427bc..8aa2a04 100644 --- a/src/utils/exportSQL/generic.js +++ b/src/utils/exportSQL/generic.js @@ -174,18 +174,14 @@ export function jsonToMySQL(obj) { .map((f) => `\`${f.name}\``) .join(", ")})` : "" - }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${ - table.indices.length > 0 - ? `\n${table.indices - .map( - (i) => - `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${i.name}\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - ) - .join("\n")}` - : "" - }`, + }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${`\n${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${i.name}\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("\n")}`}`, ) .join("\n")}\n${obj.references .map( @@ -267,20 +263,16 @@ export function jsonToPostgreSQL(obj) { .map((f) => `"${f.name}"`) .join(", ")})` : "" - }\n);\n${ - table.indices.length > 0 - ? `${table.indices - .map( - (i) => - `CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${ - i.name - }"\nON "${table.name}" (${i.fields - .map((f) => `"${f}"`) - .join(", ")});`, - ) - .join("\n")}` - : "" - }`, + }\n);\n${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${ + i.name + }"\nON "${table.name}" (${i.fields + .map((f) => `"${f}"`) + .join(", ")});`, + ) + .join("\n")}`, ) .join("\n")}\n${obj.references .map( @@ -369,20 +361,16 @@ export function jsonToSQLite(obj) { .map((f) => `"${f.name}"`) .join(", ")})${inlineFK !== "" ? ",\n" : ""}` : "" - }\t${inlineFK}\n);\n${ - table.indices.length > 0 - ? `${table.indices - .map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${ - i.name - }"\nON "${table.name}" (${i.fields - .map((f) => `"${f}"`) - .join(", ")});`, - ) - .join("\n")}` - : "" - }`; + }\t${inlineFK}\n);\n${table.indices + .map( + (i) => + `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${ + i.name + }"\nON "${table.name}" (${i.fields + .map((f) => `"${f}"`) + .join(", ")});`, + ) + .join("\n")}`; }) .join("\n"); } @@ -424,20 +412,16 @@ export function jsonToMariaDB(obj) { .map((f) => `\`${f.name}\``) .join(", ")})` : "" - }\n);${ - table.indices.length > 0 - ? `\n${table.indices - .map( - (i) => - `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ - i.name - }\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - ) - .join("\n")}` - : "" - }`, + }\n);${`\n${table.indices + .map( + (i) => + `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ + i.name + }\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("\n")}`}`, ) .join("\n")}\n${obj.references .map( @@ -496,18 +480,16 @@ export function jsonToSQLServer(obj) { .map((f) => `[${f.name}]`) .join(", ")})` : "" - }\n);\nGO\n${ - table.indices.length > 0 - ? `${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX [${ - i.name - }]\nON [${table.name}] (${i.fields - .map((f) => `[${f}]`) - .join(", ")});\nGO\n`, - )}` - : "" - }`, + }\n);\nGO\n${table.indices + .map( + (i) => + `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX [${ + i.name + }]\nON [${table.name}] (${i.fields + .map((f) => `[${f}]`) + .join(", ")});\nGO\n`, + ) + .join("")}`, ) .join("\n")}\n${obj.references .map( diff --git a/src/utils/exportSQL/mariadb.js b/src/utils/exportSQL/mariadb.js index e8ec85f..3f2ef0a 100644 --- a/src/utils/exportSQL/mariadb.js +++ b/src/utils/exportSQL/mariadb.js @@ -32,18 +32,16 @@ export function toMariaDB(diagram) { .map((f) => `\`${f.name}\``) .join(", ")})` : "" - }\n);${ - table.indices.length > 0 - ? `\n${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ - i.name - }\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - )}` - : "" - }`, + }\n);${`\n${table.indices + .map( + (i) => + `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ + i.name + }\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("")}`}`, ) .join("\n")}\n${diagram.references .map( diff --git a/src/utils/exportSQL/mysql.js b/src/utils/exportSQL/mysql.js index 8837ff5..977bf51 100644 --- a/src/utils/exportSQL/mysql.js +++ b/src/utils/exportSQL/mysql.js @@ -32,18 +32,16 @@ export function toMySQL(diagram) { .map((f) => `\`${f.name}\``) .join(", ")})` : "" - }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${ - table.indices.length > 0 - ? `\n${table.indices.map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ - i.name - }\`\nON \`${table.name}\` (${i.fields - .map((f) => `\`${f}\``) - .join(", ")});`, - )}` - : "" - }`, + }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${`\n${table.indices + .map( + (i) => + `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ + i.name + }\`\nON \`${table.name}\` (${i.fields + .map((f) => `\`${f}\``) + .join(", ")});`, + ) + .join("")}`}`, ) .join("\n")}\n${diagram.references .map( diff --git a/src/utils/exportSQL/postgres.js b/src/utils/exportSQL/postgres.js index f1201dd..5265a55 100644 --- a/src/utils/exportSQL/postgres.js +++ b/src/utils/exportSQL/postgres.js @@ -12,17 +12,17 @@ export function toPostgres(diagram) { const typeStatements = diagram.types .map( (type) => - `CREATE TYPE ${type.name} AS (\n${type.fields + `\nCREATE TYPE ${type.name} AS (\n${type.fields .map((f) => `\t${f.name} ${f.type}`) - .join("\n")}\n);\n${ + .join("\n")}\n);\n\n${ type.comment.trim() !== "" - ? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n` + ? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n\n` : "" }`, ) .join("\n"); - return `${enumStatements}\n\n${typeStatements}\n${diagram.tables + return `${enumStatements}${typeStatements}${diagram.tables .map( (table) => `CREATE TABLE "${table.name}" (\n${table.fields diff --git a/src/utils/exportSQL/sqlite.js b/src/utils/exportSQL/sqlite.js index 36dbc5c..e3fa4fc 100644 --- a/src/utils/exportSQL/sqlite.js +++ b/src/utils/exportSQL/sqlite.js @@ -28,20 +28,16 @@ export function toSqlite(diagram) { .map((f) => `"${f.name}"`) .join(", ")})${inlineFK !== "" ? ",\n" : ""}` : "" - }\t${inlineFK}\n);\n${ - table.indices.length > 0 - ? `${table.indices - .map( - (i) => - `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${ - i.name - }"\nON "${table.name}" (${i.fields - .map((f) => `"${f}"`) - .join(", ")});`, - ) - .join("\n")}` - : "" - }`; + }\t${inlineFK}\n);\n${table.indices + .map( + (i) => + `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${ + i.name + }"\nON "${table.name}" (${i.fields + .map((f) => `"${f}"`) + .join(", ")});`, + ) + .join("\n")}`; }) .join("\n"); }