Хранилища Subversion apt-scan

Редакция

Авторство | Последнее изменение | Открыть журнал | Скачать | RSS

import sqlalchemy.orm
import sqlalchemy.ext
import sqlalchemy.ext.declarative
import sqlite3

from sqlalchemy import Column, Integer, String, ForeignKey, create_engine, UniqueConstraint
from sqlalchemy.orm import relation, backref
from sqlalchemy.ext.declarative import declarative_base

DB_STRING = "sqlite:///repo.db"
Base = declarative_base(bind = create_engine(DB_STRING, module = sqlite3.dbapi2, echo = False))

class Distr(Base):
    __tablename__= 'distr'
    id = Column("d_id", Integer, primary_key=True)
    caption = Column("d_caption", String(50), nullable=False, unique=True)

    codenames = relation("Codename", primaryjoin="Distr.id == Codename.distr_id", order_by="Codename.distr_id", backref="distr")

    def __init__(self, caption):
        self.caption = caption
    def __repr__(self):
        return "<Distr('%s')>" % (self.caption)

class Codename(Base):
    __tablename__ = "codename"
    id = Column("cn_id", Integer, primary_key=True)
    distr_id = Column("d_id", Integer, ForeignKey("distr.d_id"), nullable=False)
    caption = Column("cn_caption", String(50), nullable=False)
    UniqueConstraint("distr_id", "caption")
 
    suites = relation("Suite", primaryjoin="Codename.id == Suite.codename_id", order_by="Suite.codename_id", backref="suite")

    def __init__(self, caption):
        self.caption = caption
    def __repr__(self):
        return "<Codename('%s')>" % (self.caption)


class Suite(Base):
    __tablename__ = "suite"
    id = Column("st_id", Integer, primary_key=True)
    codename_id = Column ("cn_id", Integer, ForeignKey("codename.cn_id"), nullable=False)
    caption = Column ("st_caption", String(50), nullable=False)
    UniqueConstraint ("cn_id", "st_caption")

    pathes = relation("Path", primaryjoin="Suite.id == Path.suite_id", order_by="Path.suite_id", backref="suite")
 
    def __init__(self, caption):
        self.caption = caption
    def __repr__(self):
        return "<Suite('%s')>" % (self.caption)

class Path(Base):
    __tablename__ = "path"
    suite_id = Column("st_id", Integer, ForeignKey("suite.st_id"), primary_key=True)
    path = Column ("st_caption", String(50), primary_key=True)

    def __init__(self, path):
        self.path = path
    def __repr__(self):
        return "<Path('%s')>" % (self.path)