简体   繁体   中英

SchemaCrawler Code to produce a simple .dot file

I would like produce a file which contains pairs of tables; a master on the left and a detail on the right or said another way parent and child.

In the article: "How to Visualize Your SQLite Database with One Command" using --output-file=output.png probably has some intermediate files that are used by GraphViz to provide the data. And for me a simple.dot file would be just fine. digraph Net {"Population" -> "deaths" "Population" -> "births" } What is the code necessary to do this?

It is quite easy to do this kind of customization with SchemaCrawler and a little bit of Python scripting. Take a look at How to Generate Mermaid Diagrams for Your Database . If you tweak the Python script in that article, it will generate the graph that you would like to have.

from schemacrawler.schema import TableRelationshipType # pylint: disable=import-error

print('digraph Net {')
for table in catalog.tables:
  for childTable in table.getRelatedTables(TableRelationshipType.child):
    print('  "' + table.fullName + '" -> "' + childTable.fullName + '"')
print('}')

Sualeh Fatehi, SchemaCrawler

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM