Add references in the table
This commit is contained in:
parent
f71f41d11c
commit
2bca034671
@ -5,8 +5,8 @@ export function jsonToDocumentation(obj) {
|
|||||||
|
|
||||||
const documentationSummary = obj.tables
|
const documentationSummary = obj.tables
|
||||||
.map((table) => {
|
.map((table) => {
|
||||||
return `\t- [${table.name}](#${table.name})\n`;
|
return `\t- [${table.name}](#${table.name})`;
|
||||||
}).join("");
|
}).join("\n");
|
||||||
|
|
||||||
const documentationEntities = obj.tables
|
const documentationEntities = obj.tables
|
||||||
.map((table) => {
|
.map((table) => {
|
||||||
@ -22,7 +22,9 @@ export function jsonToDocumentation(obj) {
|
|||||||
: "");
|
: "");
|
||||||
return `| **${field.name}** | ${fieldType} | ${field.primary ? "🔑 PK, " : ""}` +
|
return `| **${field.name}** | ${fieldType} | ${field.primary ? "🔑 PK, " : ""}` +
|
||||||
`${field.nullable ? "null " : "not null "}${field.unique ? ", unique" : ""}${field.increment?", autoincrement":""}` +
|
`${field.nullable ? "null " : "not null "}${field.unique ? ", unique" : ""}${field.increment?", autoincrement":""}` +
|
||||||
`${field.default ? `, default: ${field.default}` : ""} | |${field.comment ? field.comment : ""} |`;
|
`${field.default ? `, default: ${field.default}` : ""} | ` +
|
||||||
|
`${relationshipByField(table.id, obj.relationships, field.id)}` +
|
||||||
|
` |${field.comment ? field.comment : ""} |`;
|
||||||
|
|
||||||
}).join("\n");
|
}).join("\n");
|
||||||
return `### ${table.name}\n${table.comment ? table.comment : ""}\n` +
|
return `### ${table.name}\n${table.comment ? table.comment : ""}\n` +
|
||||||
@ -31,17 +33,25 @@ export function jsonToDocumentation(obj) {
|
|||||||
`${fields}\n\n`;
|
`${fields}\n\n`;
|
||||||
}).join("");
|
}).join("");
|
||||||
|
|
||||||
|
function relationshipByField(table, relationships, fieldId) {
|
||||||
|
return relationships.filter(r => r.startTableId === table && r.startFieldId === fieldId)
|
||||||
|
.map((rel) => rel.name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
const documentationRelationships = obj.relationships?.length
|
const documentationRelationships = obj.relationships?.length
|
||||||
? obj.relationships
|
? obj.relationships
|
||||||
.map((r) => {
|
.map((r) => {
|
||||||
console.log(r);
|
|
||||||
const startTable = obj.tables[r.startTableId].name;
|
const startTable = obj.tables[r.startTableId].name;
|
||||||
const endTable = obj.tables[r.endTableId].name;
|
const endTable = obj.tables[r.endTableId].name;
|
||||||
return `- **${startTable} to ${endTable}**: ${r.cardinality} (${r.comment ? r.comment : ""})\n`;
|
return `- **${startTable} to ${endTable}**: ${r.cardinality} (${r.comment ? r.comment : ""})\n`;
|
||||||
}).join("") : "";
|
}).join("") : "";
|
||||||
|
|
||||||
|
console.log(obj.tables);
|
||||||
|
console.log(obj.relationships);
|
||||||
|
|
||||||
return `# ${obj.title} Database Documentation\n## Summary\n- [Introduction](#introduction)\n- [Database Type](#database-type)\n`+
|
return `# ${obj.title} Database Documentation\n## Summary\n- [Introduction](#introduction)\n- [Database Type](#database-type)\n`+
|
||||||
`- [Table Structure](#table-structure)\n${documentationSummary}\n- [Relationships](#relationships)\n- [Database Diagram](#database-Diagram)\n`+
|
`- [Table Structure](#table-structure)\n${documentationSummary}\n- [Relationships](#relationships)\n- [Database Diagram](#database-Diagram)\n\n`+
|
||||||
`## Introduction\n${obj.notes}\n## Database type\n- **Database system:** `+
|
`## Introduction\n${obj.notes}\n## Database type\n- **Database system:** `+
|
||||||
`${obj.database.type}\n## Table structure\n\n${documentationEntities}`+
|
`${obj.database.type}\n## Table structure\n\n${documentationEntities}`+
|
||||||
`\n\n## Relationships\n${documentationRelationships}\n\n`+
|
`\n\n## Relationships\n${documentationRelationships}\n\n`+
|
||||||
|
Loading…
Reference in New Issue
Block a user