Skip to content

Commit 2da9946

Browse files
1ilitewqazxc
authored andcommitted
Fix dbml comment export (drawdb-io#699)
1 parent cbb555d commit 2da9946

File tree

1 file changed

+34
-27
lines changed

1 file changed

+34
-27
lines changed

src/utils/exportAs/dbml.js

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ function columnDefault(field, database) {
4040
return `default: ${parseDefaultDbml(field, database)}`;
4141
}
4242

43-
function columnComment(field) {
44-
if (!field.comment || field.comment.trim() === "") {
45-
return "";
46-
}
47-
48-
return `note: '${escapeQuotes(field.comment)}'`;
49-
}
50-
5143
function columnSettings(field, database) {
5244
let constraints = [];
5345

@@ -98,6 +90,23 @@ function processComment(comment) {
9890
return `'${escapeQuotes(comment)}'`;
9991
}
10092

93+
function columnComment(field) {
94+
if (!field.comment || field.comment.trim() === "") {
95+
return "";
96+
}
97+
98+
return `note: ${processComment(field.comment)}`;
99+
}
100+
101+
function processType(type) {
102+
// TODO: remove after a while
103+
if (type.toUpperCase() === "TIMESTAMP WITH TIME ZONE") {
104+
return "timestamptz";
105+
}
106+
107+
return type.toLowerCase();
108+
}
109+
101110
export function toDBML(diagram) {
102111
const generateRelString = (rel) => {
103112
const { fields: startTableFields, name: startTableName } =
@@ -134,33 +143,31 @@ export function toDBML(diagram) {
134143
`enum ${quoteIdentifier(en.name)} {\n${en.values.map((v) => `\t${quoteIdentifier(v)}`).join("\n")}\n}\n\n`,
135144
)
136145
.join("\n\n")}${enumDefinitions}${diagram.tables
137-
.map(
138-
(table) =>
139-
`Table ${quoteIdentifier(table.name)} [headercolor: ${table.color}] {\n${table.fields
140-
.map(
141-
(field) =>
142-
`\t${quoteIdentifier(field.name)} ${
143-
field.type === "ENUM" || field.type === "SET"
146+
.map(
147+
(table) =>
148+
`Table ${quoteIdentifier(table.name)} [headercolor: ${table.color}] {\n${table.fields
149+
.map(
150+
(field) =>
151+
`\t${quoteIdentifier(field.name)} ${field.type === "ENUM" || field.type === "SET"
144152
? quoteIdentifier(`${field.name}_${field.values.join("_")}_t`)
145-
: field.type.toLowerCase()
153+
: processType(field.type)
146154
}${fieldSize(
147155
field,
148156
diagram.database,
149157
)}${columnSettings(field, diagram.database)}`,
150158
)
151159
.join("\n")}${table.indices.length > 0
152160
? "\n\n\tindexes {\n" +
153-
table.indices
154-
.map(
155-
(index) =>
156-
`\t\t(${index.fields
157-
.map((f) => quoteIdentifier(f))
158-
.join(", ")}) [ name: '${
159-
index.name
160-
}'${index.unique ? ", unique" : ""} ]`,
161-
)
162-
.join("\n") +
163-
"\n\t}"
161+
table.indices
162+
.map(
163+
(index) =>
164+
`\t\t(${index.fields
165+
.map((f) => quoteIdentifier(f))
166+
.join(", ")}) [ name: '${index.name
167+
}'${index.unique ? ", unique" : ""} ]`,
168+
)
169+
.join("\n") +
170+
"\n\t}"
164171
: ""
165172
}${table.comment && table.comment.trim() !== ""
166173
? `\n\n\tNote: ${processComment(table.comment)}`

0 commit comments

Comments
 (0)