Skip to content

Commit

Permalink
Merge pull request #34 from Software-Developers-IRL/f/lastlink
Browse files Browse the repository at this point in the history
F/lastlink improved space handling and mermaid format
  • Loading branch information
lastlink authored Oct 1, 2022
2 parents 95e0014 + 3c81bb2 commit 936b24b
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions samples/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
print('')
# generate entity tables
for table in catalog.tables:
print(' ' + table.fullName + ' {')
tableFullName = re.sub("[\"\']", "", table.fullName).replace(" ","_")
print(' ' + tableFullName + ' {')
for column in table.columns:
# // need to remove quotes and spaces
# get all column attributes for debugging
Expand Down Expand Up @@ -47,14 +48,25 @@
# generate relationships, need to display keys in the description for sql generation
# https://www.tabnine.com/code/java/methods/schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder/includeGreppedColumns
for table in catalog.tables:
tableOriginal = re.sub("[\"\']", "", table.fullName)
tableFullName = tableOriginal.replace(" ","_")
# print (tableFullName)
addSpace = False
for foreignKeys in table.foreignKeys:
relationshipTxt = str(foreignKeys.primaryKeyTable.primaryKey.columns) + " to " + str(foreignKeys.columns)
relationshipTxt = "\"" + re.sub("[\"]", "\'", relationshipTxt) + "\""
print(' ' + table.fullName + ' ||--o{ ' + str(foreignKeys.foreignKeyTable) + ' : '+ relationshipTxt)
print('')
fkTableOriginal = str(foreignKeys.primaryKeyTable)
fkTableFullName = fkTableOriginal.replace(" ", "_")
if(tableFullName != fkTableFullName):
addSpace = True
relationshipTxt = str(foreignKeys.primaryKeyTable.primaryKey.columns) + " to " + str(foreignKeys.columns)
relationshipTxt = "\"" + re.sub("[\"]", "\'", relationshipTxt) + "\""
relationshipTxt = relationshipTxt.replace(tableOriginal,tableFullName).replace(fkTableOriginal, fkTableFullName)
# str(foreignKeys.foreignKeyTable)
print(' ' + fkTableOriginal + ' ||--o{ ' + tableFullName + ' : '+ relationshipTxt)
if(addSpace):
print('')
# old way
for table in catalog.tables:
for childTable in table.getRelatedTables(TableRelationshipType.child):
print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
print('')
print('```')
# for table in catalog.tables:
# for childTable in table.getRelatedTables(TableRelationshipType.child):
# print(' ' + table.name + ' ||--o{ ' + childTable.name + ' : "foreign key"')
# print('')
# print('```')

0 comments on commit 936b24b

Please sign in to comment.