Skip to content

Commit 936b24b

Browse files
authored
Merge pull request #34 from Software-Developers-IRL/f/lastlink
F/lastlink improved space handling and mermaid format
2 parents 95e0014 + 3c81bb2 commit 936b24b

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

samples/mermaid.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
print('')
1515
# generate entity tables
1616
for table in catalog.tables:
17-
print(' ' + table.fullName + ' {')
17+
tableFullName = re.sub("[\"\']", "", table.fullName).replace(" ","_")
18+
print(' ' + tableFullName + ' {')
1819
for column in table.columns:
1920
# // need to remove quotes and spaces
2021
# get all column attributes for debugging
@@ -47,14 +48,25 @@
4748
# generate relationships, need to display keys in the description for sql generation
4849
# https://www.tabnine.com/code/java/methods/schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder/includeGreppedColumns
4950
for table in catalog.tables:
51+
tableOriginal = re.sub("[\"\']", "", table.fullName)
52+
tableFullName = tableOriginal.replace(" ","_")
53+
# print (tableFullName)
54+
addSpace = False
5055
for foreignKeys in table.foreignKeys:
51-
relationshipTxt = str(foreignKeys.primaryKeyTable.primaryKey.columns) + " to " + str(foreignKeys.columns)
52-
relationshipTxt = "\"" + re.sub("[\"]", "\'", relationshipTxt) + "\""
53-
print(' ' + table.fullName + ' ||--o{ ' + str(foreignKeys.foreignKeyTable) + ' : '+ relationshipTxt)
54-
print('')
56+
fkTableOriginal = str(foreignKeys.primaryKeyTable)
57+
fkTableFullName = fkTableOriginal.replace(" ", "_")
58+
if(tableFullName != fkTableFullName):
59+
addSpace = True
60+
relationshipTxt = str(foreignKeys.primaryKeyTable.primaryKey.columns) + " to " + str(foreignKeys.columns)
61+
relationshipTxt = "\"" + re.sub("[\"]", "\'", relationshipTxt) + "\""
62+
relationshipTxt = relationshipTxt.replace(tableOriginal,tableFullName).replace(fkTableOriginal, fkTableFullName)
63+
# str(foreignKeys.foreignKeyTable)
64+
print(' ' + fkTableOriginal + ' ||--o{ ' + tableFullName + ' : '+ relationshipTxt)
65+
if(addSpace):
66+
print('')
5567
# old way
56-
for table in catalog.tables:
57-
for childTable in table.getRelatedTables(TableRelationshipType.child):
58-
print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
59-
print('')
60-
print('```')
68+
# for table in catalog.tables:
69+
# for childTable in table.getRelatedTables(TableRelationshipType.child):
70+
# print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
71+
# print('')
72+
# print('```')

0 commit comments

Comments
 (0)