| 1 |
========= |
| 2 |
sadisplay |
| 3 |
========= |
| 4 |
|
| 5 |
About |
| 6 |
===== |
| 7 |
Simple package for describing SQLAlchemy schema and display raw database |
| 8 |
tables. Relation detecting by `ForeignKey` columns. |
| 9 |
Supports mapped class inherit. BSD licensed. |
| 10 |
|
| 11 |
|
| 12 |
Output formats: |
| 13 |
|
| 14 |
* `PlantUML <http://plantuml.sourceforge.net/>`_ class diagram |
| 15 |
* `DOT <http://www.graphviz.org/>`_ graphviz directed graphs |
| 16 |
|
| 17 |
|
| 18 |
Requirements |
| 19 |
============ |
| 20 |
* python >= 2.5 |
| 21 |
* SQLAlchemy >= 0.5 |
| 22 |
|
| 23 |
|
| 24 |
Install |
| 25 |
======= |
| 26 |
|
| 27 |
:: |
| 28 |
|
| 29 |
pip install sadisplay |
| 30 |
|
| 31 |
From bitbucket:: |
| 32 |
|
| 33 |
pip install http://bitbucket.org/estin/sadisplay/get/tip.tar.gz |
| 34 |
# or |
| 35 |
easy_install http://bitbucket.org/estin/sadisplay/get/tip.tar.gz |
| 36 |
|
| 37 |
|
| 38 |
Usage |
| 39 |
===== |
| 40 |
|
| 41 |
Write simple script in your project environment:: |
| 42 |
|
| 43 |
import codecs |
| 44 |
import sadisplay |
| 45 |
from yourapp import model |
| 46 |
|
| 47 |
desc = sadisplay.describe( |
| 48 |
[getattr(model, attr) for attr in dir(model)], |
| 49 |
show_methods=True, |
| 50 |
show_properties=True, |
| 51 |
show_indexes=True, |
| 52 |
) |
| 53 |
with codecs.open('schema.plantuml', 'w', encoding='utf-8') as f: |
| 54 |
f.write(sadisplay.plantuml(desc)) |
| 55 |
with codecs.open('schema.dot', 'w', encoding='utf-8') as f: |
| 56 |
f.write(sadisplay.dot(desc)) |
| 57 |
|
| 58 |
# Or only part of schema |
| 59 |
desc = sadisplay.describe([model.User, model.Group, model.Persmission]) |
| 60 |
with codecs.open('auth.plantuml', 'w', encoding='utf-8') as f: |
| 61 |
f.write(sadisplay.plantuml(desc)) |
| 62 |
with codecs.open('auth.dot', 'w', encoding='utf-8') as f: |
| 63 |
f..write(sadisplay.dot(desc)) |
| 64 |
|
| 65 |
|
| 66 |
Render PlantUML class diagram:: |
| 67 |
|
| 68 |
$ java -jar plantuml.jar schema.plantuml |
| 69 |
|
| 70 |
# or for svg format |
| 71 |
$ java -jar plantuml.jar -Tsvg schema.plantuml |
| 72 |
|
| 73 |
|
| 74 |
Render graph by graphviz:: |
| 75 |
|
| 76 |
$ dot -Tpng schema.dot > schema.png |
| 77 |
|
| 78 |
|
| 79 |
Also you can display you sql database tables by reflecting feature:: |
| 80 |
|
| 81 |
$ sadisplay -u <URL connection string to db> -r dot > schema.dot |
| 82 |
$ dot -Tpng schema.dot > schema.png |