sqlalchemy模式显示脚本
sadispla的Python项目详细描述
要求
- python>;=2.5
- sqlalchemy>;=0.5
安装
pip install sadisplay
来自Bitbucket:
pip install http://bitbucket.org/estin/sadisplay/get/tip.tar.gz # or easy_install http://bitbucket.org/estin/sadisplay/get/tip.tar.gz
用法
在项目环境中编写简单的脚本:
import codecs import sadisplay from yourapp import model desc = sadisplay.describe( [getattr(model, attr) for attr in dir(model)], show_methods=True, show_properties=True, show_indexes=True, ) with codecs.open('schema.plantuml', 'w', encoding='utf-8') as f: f.write(sadisplay.plantuml(desc)) with codecs.open('schema.dot', 'w', encoding='utf-8') as f: f.write(sadisplay.dot(desc)) # Or only part of schema desc = sadisplay.describe([model.User, model.Group, model.Persmission]) with codecs.open('auth.plantuml', 'w', encoding='utf-8') as f: f.write(sadisplay.plantuml(desc)) with codecs.open('auth.dot', 'w', encoding='utf-8') as f: f..write(sadisplay.dot(desc))
呈现plantuml类图:
$ java -jar plantuml.jar schema.plantuml # or for svg format $ java -jar plantuml.jar -Tsvg schema.plantuml
按图形呈现图形:
$ dot -Tpng schema.dot > schema.png
您还可以通过反射功能来显示SQL数据库表:
$ sadisplay -u <URL connection string to db> -r dot > schema.dot $ dot -Tpng schema.dot > schema.png