Commits

Evgeniy Tatarkin committed cac33a5

update for 0.3.1 version

  • Participants
  • Parent commits 1478a48

Comments (0)

Files changed (3)

 = sadisplay =
 
-Simple package for describing SQLAlchemy schema. Works with mapped classes. Relation detecting by ForeignKey columns. Supports mapped class inherit.
+Simple package for describing SQLAlchemy schema and display raw database tables by reflecting feature.
+Works with mapped classes and raw tables. Relation detecting by ForeignKey columns. Supports mapped class inherit.
 
 Output formats:
 * [[http://plantuml.sourceforge.net/|PlantUML]] class diagram
+* [[http://www.graphviz.org/|DOT]]_ graphviz directed graphs
 
 
 [[Gallery]]
 
 desc = sadisplay.describe([getattr(model, attr) for attr in dir(model)])
 open('schema.plantuml', 'w').write(sadisplay.plantuml(desc))
+open('schema.dot', 'w').write(sadisplay.dot(desc))
 
 # Or only part of schema
 desc = sadisplay.describe([model.User, model.Group, model.Permission])
 open('auth.plantuml', 'w').write(sadisplay.plantuml(desc))
+open('auth.dot', 'w').write(sadisplay.dot(desc))
 
 }}}
 
 {{{
 $ java -jar plantuml.jar -Tsvg schema.plantuml
 }}}
-{{https://bytebucket.org/estin/sadisplay/wiki/static/schema.png|Schema}}
-
+
+=== Reflection tables from database ===
+
+{{{
+    sadisplay -u <URL connection string to db> > schema.dot
+    dot -Tpng schema.dot > schema.png
+}}}
+
+
+== Example ==
+
+{{{
+#!python
+# -*- coding: utf-8 -*-
+from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey
+from sqlalchemy.ext.declarative import declarative_base
+from sqlalchemy.orm import relation, mapper
+
+
+BASE = declarative_base()
+
+
+class User(BASE):
+    __tablename__ = 'user_table'
+
+    id = Column(Integer, primary_key=True)
+    name = Column(Unicode(50))
+
+    def login(self):
+        pass
+
+    def __repr__(self):
+        pass
+
+
+class Admin(User):
+    __tablename__ = 'admin_table'
+    __mapper_args__ = {'polymorphic_identity': 'user_table'}
+
+    id = Column(Integer, ForeignKey('user_table.id'), primary_key=True)
+    phone = Column(Unicode(50))
+
+    def permissions(self):
+        pass
+
+    def __unicode__(self):
+        pass
+
+
+class Address(BASE):
+    __tablename__ = 'address_table'
+
+    id = Column(Integer, primary_key=True)
+    user_id = Column(Integer, ForeignKey('user_table.id'))
+    user = relation(User, backref="address")
+
+
+books = Table('books', BASE.metadata,
+    Column('id', Integer, primary_key=True),
+    Column('title', Unicode(200), nullable=False),
+    Column('user_id', Integer, ForeignKey('user_table.id')),
+)
+
+
+class Book(object):
+    pass
+
+
+mapper(Book, books, {'user': relation(User, backref='books')})
+
+
+# Not mapped table
+notes = Table('notes', BASE.metadata,
+    Column('id', Integer, primary_key=True),
+    Column('name', Unicode(200), nullable=False),
+    Column('user_id', Integer, ForeignKey('user_table.id')),
+)
+}}}
+
+
+Graphviz renderer
+{{https://bitebucket.org/estin/sadisplay/wiki/static/schema2.png|Schema1}}
+
+PlantUML renderer
+{{https://bitebucket.org/estin/sadisplay/wiki/static/schema.png|Schema2}}
+
 [[Gallery]]

File static/schema.png

Old
Old image
New
New image

File static/schema2.png

Added
New image