14
14
print ('' )
15
15
# generate entity tables
16
16
for table in catalog .tables :
17
- print (' ' + table .fullName + ' {' )
17
+ tableFullName = re .sub ("[\" \' ]" , "" , table .fullName ).replace (" " ,"_" )
18
+ print (' ' + tableFullName + ' {' )
18
19
for column in table .columns :
19
20
# // need to remove quotes and spaces
20
21
# get all column attributes for debugging
47
48
# generate relationships, need to display keys in the description for sql generation
48
49
# https://www.tabnine.com/code/java/methods/schemacrawler.schemacrawler.SchemaCrawlerOptionsBuilder/includeGreppedColumns
49
50
for table in catalog .tables :
51
+ tableOriginal = re .sub ("[\" \' ]" , "" , table .fullName )
52
+ tableFullName = tableOriginal .replace (" " ,"_" )
53
+ # print (tableFullName)
54
+ addSpace = False
50
55
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 ('' )
55
67
# 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