Skip to content

Commit 2bca034

Browse files
committed
Add references in the table
1 parent f71f41d commit 2bca034

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/utils/exportAs/documentation.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ export function jsonToDocumentation(obj) {
55

66
const documentationSummary = obj.tables
77
.map((table) => {
8-
return `\t- [${table.name}](#${table.name})\n`;
9-
}).join("");
8+
return `\t- [${table.name}](#${table.name})`;
9+
}).join("\n");
1010

1111
const documentationEntities = obj.tables
1212
.map((table) => {
@@ -22,7 +22,9 @@ export function jsonToDocumentation(obj) {
2222
: "");
2323
return `| **${field.name}** | ${fieldType} | ${field.primary ? "🔑 PK, " : ""}` +
2424
`${field.nullable ? "null " : "not null "}${field.unique ? ", unique" : ""}${field.increment?", autoincrement":""}` +
25-
`${field.default ? `, default: ${field.default}` : ""} | |${field.comment ? field.comment : ""} |`;
25+
`${field.default ? `, default: ${field.default}` : ""} | ` +
26+
`${relationshipByField(table.id, obj.relationships, field.id)}` +
27+
` |${field.comment ? field.comment : ""} |`;
2628

2729
}).join("\n");
2830
return `### ${table.name}\n${table.comment ? table.comment : ""}\n` +
@@ -31,17 +33,25 @@ export function jsonToDocumentation(obj) {
3133
`${fields}\n\n`;
3234
}).join("");
3335

36+
function relationshipByField(table, relationships, fieldId) {
37+
return relationships.filter(r => r.startTableId === table && r.startFieldId === fieldId)
38+
.map((rel) => rel.name);
39+
40+
}
41+
3442
const documentationRelationships = obj.relationships?.length
3543
? obj.relationships
3644
.map((r) => {
37-
console.log(r);
3845
const startTable = obj.tables[r.startTableId].name;
3946
const endTable = obj.tables[r.endTableId].name;
4047
return `- **${startTable} to ${endTable}**: ${r.cardinality} (${r.comment ? r.comment : ""})\n`;
4148
}).join("") : "";
4249

50+
console.log(obj.tables);
51+
console.log(obj.relationships);
52+
4353
return `# ${obj.title} Database Documentation\n## Summary\n- [Introduction](#introduction)\n- [Database Type](#database-type)\n`+
44-
`- [Table Structure](#table-structure)\n${documentationSummary}\n- [Relationships](#relationships)\n- [Database Diagram](#database-Diagram)\n`+
54+
`- [Table Structure](#table-structure)\n${documentationSummary}\n- [Relationships](#relationships)\n- [Database Diagram](#database-Diagram)\n\n`+
4555
`## Introduction\n${obj.notes}\n## Database type\n- **Database system:** `+
4656
`${obj.database.type}\n## Table structure\n\n${documentationEntities}`+
4757
`\n\n## Relationships\n${documentationRelationships}\n\n`+

0 commit comments

Comments
 (0)