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}\``) .map((f) => `\`${f.name}\``)
.join(", ")})` .join(", ")})`
: "" : ""
}\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${ }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${`\n${table.indices
table.indices.length > 0 .map(
? `\n${table.indices (i) =>
.map( `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${i.name}\`\nON \`${table.name}\` (${i.fields
(i) => .map((f) => `\`${f}\``)
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${i.name}\`\nON \`${table.name}\` (${i.fields .join(", ")});`,
.map((f) => `\`${f}\``) )
.join(", ")});`, .join("\n")}`}`,
)
.join("\n")}`
: ""
}`,
) )
.join("\n")}\n${obj.references .join("\n")}\n${obj.references
.map( .map(
@ -267,20 +263,16 @@ export function jsonToPostgreSQL(obj) {
.map((f) => `"${f.name}"`) .map((f) => `"${f.name}"`)
.join(", ")})` .join(", ")})`
: "" : ""
}\n);\n${ }\n);\n${table.indices
table.indices.length > 0 .map(
? `${table.indices (i) =>
.map( `CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${
(i) => i.name
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX "${ }"\nON "${table.name}" (${i.fields
i.name .map((f) => `"${f}"`)
}"\nON "${table.name}" (${i.fields .join(", ")});`,
.map((f) => `"${f}"`) )
.join(", ")});`, .join("\n")}`,
)
.join("\n")}`
: ""
}`,
) )
.join("\n")}\n${obj.references .join("\n")}\n${obj.references
.map( .map(
@ -369,20 +361,16 @@ export function jsonToSQLite(obj) {
.map((f) => `"${f.name}"`) .map((f) => `"${f.name}"`)
.join(", ")})${inlineFK !== "" ? ",\n" : ""}` .join(", ")})${inlineFK !== "" ? ",\n" : ""}`
: "" : ""
}\t${inlineFK}\n);\n${ }\t${inlineFK}\n);\n${table.indices
table.indices.length > 0 .map(
? `${table.indices (i) =>
.map( `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
(i) => i.name
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${ }"\nON "${table.name}" (${i.fields
i.name .map((f) => `"${f}"`)
}"\nON "${table.name}" (${i.fields .join(", ")});`,
.map((f) => `"${f}"`) )
.join(", ")});`, .join("\n")}`;
)
.join("\n")}`
: ""
}`;
}) })
.join("\n"); .join("\n");
} }
@ -424,20 +412,16 @@ export function jsonToMariaDB(obj) {
.map((f) => `\`${f.name}\``) .map((f) => `\`${f.name}\``)
.join(", ")})` .join(", ")})`
: "" : ""
}\n);${ }\n);${`\n${table.indices
table.indices.length > 0 .map(
? `\n${table.indices (i) =>
.map( `CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${
(i) => i.name
`CREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ }\`\nON \`${table.name}\` (${i.fields
i.name .map((f) => `\`${f}\``)
}\`\nON \`${table.name}\` (${i.fields .join(", ")});`,
.map((f) => `\`${f}\``) )
.join(", ")});`, .join("\n")}`}`,
)
.join("\n")}`
: ""
}`,
) )
.join("\n")}\n${obj.references .join("\n")}\n${obj.references
.map( .map(
@ -496,18 +480,16 @@ export function jsonToSQLServer(obj) {
.map((f) => `[${f.name}]`) .map((f) => `[${f.name}]`)
.join(", ")})` .join(", ")})`
: "" : ""
}\n);\nGO\n${ }\n);\nGO\n${table.indices
table.indices.length > 0 .map(
? `${table.indices.map( (i) =>
(i) => `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX [${
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX [${ i.name
i.name }]\nON [${table.name}] (${i.fields
}]\nON [${table.name}] (${i.fields .map((f) => `[${f}]`)
.map((f) => `[${f}]`) .join(", ")});\nGO\n`,
.join(", ")});\nGO\n`, )
)}` .join("")}`,
: ""
}`,
) )
.join("\n")}\n${obj.references .join("\n")}\n${obj.references
.map( .map(

View File

@ -32,18 +32,16 @@ export function toMariaDB(diagram) {
.map((f) => `\`${f.name}\``) .map((f) => `\`${f.name}\``)
.join(", ")})` .join(", ")})`
: "" : ""
}\n);${ }\n);${`\n${table.indices
table.indices.length > 0 .map(
? `\n${table.indices.map( (i) =>
(i) => `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ i.name
i.name }\`\nON \`${table.name}\` (${i.fields
}\`\nON \`${table.name}\` (${i.fields .map((f) => `\`${f}\``)
.map((f) => `\`${f}\``) .join(", ")});`,
.join(", ")});`, )
)}` .join("")}`}`,
: ""
}`,
) )
.join("\n")}\n${diagram.references .join("\n")}\n${diagram.references
.map( .map(

View File

@ -32,18 +32,16 @@ export function toMySQL(diagram) {
.map((f) => `\`${f.name}\``) .map((f) => `\`${f.name}\``)
.join(", ")})` .join(", ")})`
: "" : ""
}\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${ }\n)${table.comment ? ` COMMENT='${table.comment}'` : ""};\n${`\n${table.indices
table.indices.length > 0 .map(
? `\n${table.indices.map( (i) =>
(i) => `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${
`\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX \`${ i.name
i.name }\`\nON \`${table.name}\` (${i.fields
}\`\nON \`${table.name}\` (${i.fields .map((f) => `\`${f}\``)
.map((f) => `\`${f}\``) .join(", ")});`,
.join(", ")});`, )
)}` .join("")}`}`,
: ""
}`,
) )
.join("\n")}\n${diagram.references .join("\n")}\n${diagram.references
.map( .map(

View File

@ -12,17 +12,17 @@ export function toPostgres(diagram) {
const typeStatements = diagram.types const typeStatements = diagram.types
.map( .map(
(type) => (type) =>
`CREATE TYPE ${type.name} AS (\n${type.fields `\nCREATE TYPE ${type.name} AS (\n${type.fields
.map((f) => `\t${f.name} ${f.type}`) .map((f) => `\t${f.name} ${f.type}`)
.join("\n")}\n);\n${ .join("\n")}\n);\n\n${
type.comment.trim() !== "" type.comment.trim() !== ""
? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n` ? `\nCOMMENT ON TYPE "${type.name}" IS '${type.comment}';\n\n`
: "" : ""
}`, }`,
) )
.join("\n"); .join("\n");
return `${enumStatements}\n\n${typeStatements}\n${diagram.tables return `${enumStatements}${typeStatements}${diagram.tables
.map( .map(
(table) => (table) =>
`CREATE TABLE "${table.name}" (\n${table.fields `CREATE TABLE "${table.name}" (\n${table.fields

View File

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