Free, simple, and intuitive online database diagram editor and SQL generator.
JavaScript databasedatabase-designdatabase-diagramdatabase-schemadbmldiagram-editoreditorer-diagramerderdiagramindexeddbmariadbmcporacle-databaseoracle-dbpostgresqlschema-designsqlsql-serversqlite
Remove unnecessary commas in export index statements
1ilit6fee6553f180
diff --git a/src/utils/exportSQL/generic.js b/src/utils/exportSQL/generic.jsindex 16427bc6..8aa2a045 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.jsindex e8ec85f2..3f2ef0ad 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.jsindex 8837ff5f..977bf519 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.jsindex f1201dd7..5265a550 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.fieldsdiff --git a/src/utils/exportSQL/sqlite.js b/src/utils/exportSQL/sqlite.jsindex 36dbc5c3..e3fa4fca 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");}