Debian Codegraph @

examples/e01.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 from sqlalchemy import Table, Column, Integer, Unicode, ForeignKey, Index
3 from sqlalchemy.ext.declarative import declarative_base
4 from sqlalchemy.orm import relation, mapper
5
6 BASE = declarative_base()
7
8
9 class User(BASE):
10 __tablename__ = 'user_table'
11
12 id = Column(Integer, primary_key=True)
13 name = Column(Unicode(50))
14
15 def login(self):
16 pass
17
18 def __repr__(self):
19 pass
20
21
22 class Admin(User):
23 __tablename__ = 'admin_table'
24 __mapper_args__ = {'polymorphic_identity': 'user_table'}
25
26 id = Column(Integer, ForeignKey('user_table.id'), primary_key=True)
27 phone = Column(Unicode(50))
28
29 def permissions(self):
30 pass
31
32 def __unicode__(self):
33 pass
34
35
36 class Address(BASE):
37 __tablename__ = 'address_table'
38
39 id = Column(Integer, primary_key=True)
40 user_id = Column(Integer, ForeignKey('user_table.id'))
41 user = relation(User, backref="address")
42
43
44 books = Table(
45 'books',
46 BASE.metadata,
47 Column('id', Integer, primary_key=True),
48 Column('title', Unicode(200), nullable=False),
49 Column('user_id', Integer, ForeignKey('user_table.id')), )
50
51 Index("ix_user_title", books.c.user_id, books.c.title)
52
53
54 class Book(object):
55 pass
56
57
58 mapper(Book, books, {'user': relation(User, backref='books')})
59
60 # Not mapped table
61 notes = Table(
62 'notes',
63 BASE.metadata,
64 Column('id', Integer, primary_key=True),
65 Column('name', Unicode(200), nullable=False),
66 Column('user_id', Integer, ForeignKey('user_table.id')), )
67
68 if __name__ == '__main__':
69 import sadisplay
70
71 desc = sadisplay.describe(globals().values())
72
73 with open('schema-plantuml.plantuml', 'w') as f:
74 f.write(sadisplay.plantuml(desc))
75
76 with open('schema-dot.dot', 'w') as f:
77 f.write(sadisplay.dot(desc))
78
79 print("""Done. Next:
80 $ plantuml schema-plantuml.plantuml
81 $ dot -Tpng schema-dot.dot > schema-dot.png
82 """)