@@ -5,8 +5,8 @@ export function jsonToDocumentation(obj) {
5
5
6
6
const documentationSummary = obj . tables
7
7
. map ( ( table ) => {
8
- return `\t- [${ table . name } ](#${ table . name } )\n ` ;
9
- } ) . join ( "" ) ;
8
+ return `\t- [${ table . name } ](#${ table . name } )` ;
9
+ } ) . join ( "\n " ) ;
10
10
11
11
const documentationEntities = obj . tables
12
12
. map ( ( table ) => {
@@ -22,7 +22,9 @@ export function jsonToDocumentation(obj) {
22
22
: "" ) ;
23
23
return `| **${ field . name } ** | ${ fieldType } | ${ field . primary ? "🔑 PK, " : "" } ` +
24
24
`${ 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 : "" } |` ;
26
28
27
29
} ) . join ( "\n" ) ;
28
30
return `### ${ table . name } \n${ table . comment ? table . comment : "" } \n` +
@@ -31,17 +33,25 @@ export function jsonToDocumentation(obj) {
31
33
`${ fields } \n\n` ;
32
34
} ) . join ( "" ) ;
33
35
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
+
34
42
const documentationRelationships = obj . relationships ?. length
35
43
? obj . relationships
36
44
. map ( ( r ) => {
37
- console . log ( r ) ;
38
45
const startTable = obj . tables [ r . startTableId ] . name ;
39
46
const endTable = obj . tables [ r . endTableId ] . name ;
40
47
return `- **${ startTable } to ${ endTable } **: ${ r . cardinality } (${ r . comment ? r . comment : "" } )\n` ;
41
48
} ) . join ( "" ) : "" ;
42
49
50
+ console . log ( obj . tables ) ;
51
+ console . log ( obj . relationships ) ;
52
+
43
53
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 ` +
45
55
`## Introduction\n${ obj . notes } \n## Database type\n- **Database system:** ` +
46
56
`${ obj . database . type } \n## Table structure\n\n${ documentationEntities } ` +
47
57
`\n\n## Relationships\n${ documentationRelationships } \n\n` +
0 commit comments