Remove unnecessary commas in export index statements

This commit is contained in:
1ilit 2024-07-08 04:19:14 +03:00
parent 159dcca4dc
commit 6fee6553f1
5 changed files with 82 additions and 108 deletions

View File

@ -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
}\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")}`}`,
)
.join("\n")}\n${obj.references
.map(
@ -267,9 +263,7 @@ export function jsonToPostgreSQL(obj) {
.map((f) => `"${f.name}"`)
.join(", ")})`
: ""
}\n);\n${
table.indices.length > 0
? `${table.indices
}\n);\n${table.indices
.map(
(i) =>
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${
@ -278,9 +272,7 @@ export function jsonToPostgreSQL(obj) {
.map((f) => `"${f}"`)
.join(", ")});`,
)
.join("\n")}`
: ""
}`,
.join("\n")}`,
)
.join("\n")}\n${obj.references
.map(
@ -369,9 +361,7 @@ export function jsonToSQLite(obj) {
.map((f) => `"${f.name}"`)
.join(", ")})${inlineFK !== "" ? ",\n" : ""}`
: ""
}\t${inlineFK}\n);\n${
table.indices.length > 0
? `${table.indices
}\t${inlineFK}\n);\n${table.indices
.map(
(i) =>
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
@ -380,9 +370,7 @@ export function jsonToSQLite(obj) {
.map((f) => `"${f}"`)
.join(", ")});`,
)
.join("\n")}`
: ""
}`;
.join("\n")}`;
})
.join("\n");
}
@ -424,9 +412,7 @@ export function jsonToMariaDB(obj) {
.map((f) => `\`${f.name}\``)
.join(", ")})`
: ""
}\n);${
table.indices.length > 0
? `\n${table.indices
}\n);${`\n${table.indices
.map(
(i) =>
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${
@ -435,9 +421,7 @@ export function jsonToMariaDB(obj) {
.map((f) => `\`${f}\``)
.join(", ")});`,
)
.join("\n")}`
: ""
}`,
.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(
}\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(

View File

@ -32,18 +32,16 @@ export function toMariaDB(diagram) {
.map((f) => `\`${f.name}\``)
.join(", ")})`
: ""
}\n);${
table.indices.length > 0
? `\n${table.indices.map(
}\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(

View File

@ -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(
}\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(

View File

@ -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

View File

@ -28,9 +28,7 @@ export function toSqlite(diagram) {
.map((f) => `"${f.name}"`)
.join(", ")})${inlineFK !== "" ? ",\n" : ""}`
: ""
}\t${inlineFK}\n);\n${
table.indices.length > 0
? `${table.indices
}\t${inlineFK}\n);\n${table.indices
.map(
(i) =>
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
@ -39,9 +37,7 @@ export function toSqlite(diagram) {
.map((f) => `"${f}"`)
.join(", ")});`,
)
.join("\n")}`
: ""
}`;
.join("\n")}`;
})
.join("\n");
}