Содержимое файла | Последнее изменение | Открыть журнал | RSS
Редакция | Автор | № строки | Строка |
---|---|---|---|
2 | ddosia | 1 | import sqlalchemy.orm |
2 | import sqlalchemy.ext |
||
3 | import sqlalchemy.ext.declarative |
||
4 | import sqlite3 |
||
5 | |||
6 | from sqlalchemy import Column, Integer, String, ForeignKey, create_engine, UniqueConstraint |
||
7 | from sqlalchemy.orm import relation, backref |
||
8 | from sqlalchemy.ext.declarative import declarative_base |
||
9 | |||
10 | DB_STRING = "sqlite:///repo.db" |
||
11 | Base = declarative_base(bind = create_engine(DB_STRING, module = sqlite3.dbapi2, echo = False)) |
||
12 | |||
13 | class Distr(Base): |
||
14 | __tablename__= 'distr' |
||
15 | id = Column("d_id", Integer, primary_key=True) |
||
16 | caption = Column("d_caption", String(50), nullable=False, unique=True) |
||
17 | |||
18 | codenames = relation("Codename", primaryjoin="Distr.id == Codename.distr_id", order_by="Codename.distr_id", backref="distr") |
||
19 | |||
20 | def __init__(self, caption): |
||
21 | self.caption = caption |
||
22 | def __repr__(self): |
||
23 | return "<Distr('%s')>" % (self.caption) |
||
24 | |||
25 | class Codename(Base): |
||
26 | __tablename__ = "codename" |
||
27 | id = Column("cn_id", Integer, primary_key=True) |
||
28 | distr_id = Column("d_id", Integer, ForeignKey("distr.d_id"), nullable=False) |
||
29 | caption = Column("cn_caption", String(50), nullable=False) |
||
30 | UniqueConstraint("distr_id", "caption") |
||
31 | |||
32 | suites = relation("Suite", primaryjoin="Codename.id == Suite.codename_id", order_by="Suite.codename_id", backref="suite") |
||
33 | |||
34 | def __init__(self, caption): |
||
35 | self.caption = caption |
||
36 | def __repr__(self): |
||
37 | return "<Codename('%s')>" % (self.caption) |
||
38 | |||
39 | |||
40 | class Suite(Base): |
||
41 | __tablename__ = "suite" |
||
42 | id = Column("st_id", Integer, primary_key=True) |
||
43 | codename_id = Column ("cn_id", Integer, ForeignKey("codename.cn_id"), nullable=False) |
||
44 | caption = Column ("st_caption", String(50), nullable=False) |
||
45 | UniqueConstraint ("cn_id", "st_caption") |
||
46 | |||
47 | pathes = relation("Path", primaryjoin="Suite.id == Path.suite_id", order_by="Path.suite_id", backref="suite") |
||
48 | |||
49 | def __init__(self, caption): |
||
50 | self.caption = caption |
||
51 | def __repr__(self): |
||
52 | return "<Suite('%s')>" % (self.caption) |
||
53 | |||
54 | class Path(Base): |
||
55 | __tablename__ = "path" |
||
56 | suite_id = Column("st_id", Integer, ForeignKey("suite.st_id"), primary_key=True) |
||
57 | path = Column ("st_caption", String(50), primary_key=True) |
||
58 | |||
59 | def __init__(self, path): |
||
60 | self.path = path |
||
61 | def __repr__(self): |
||
62 | return "<Path('%s')>" % (self.path) |
||
63 |