@@ -0,0 +1,3427 @@
+from sqlalchemy import Column, Integer, String, Numeric, and_%0Afrom sqlalchemy.ext.declarative import declarative_base, DeferredReflection%0Afrom sqlalchemy.ext.declarative import declared_attr%0A%0ABase = declarative_base(cls=DeferredReflection)%0A%0Aclass UniqueMixin(object):%0A    @classmethod%0A    def unique_hash(cls, *arg, **kw):%0A        raise NotImplementedError()%0A%0A    @classmethod%0A    def unique_filter(cls, query, *arg, **kw):%0A        raise NotImplementedError()%0A%0A    @classmethod%0A    def as_unique(cls, session, *arg, **kw):%0A        return _unique(%0A                    session,%0A                    cls,%0A                    cls.unique_hash,%0A                    cls.unique_filter,%0A                    cls,%0A                    arg, kw)%0A%0Adef _unique(session, cls, hashfunc, queryfunc, constructor, arg, kw):%0A    cache = getattr(session, '_unique_cache', None)%0A    if cache is None:%0A        session._unique_cache = cache = %7B%7D%0A%0A    key = (cls, hashfunc(*arg, **kw))%0A    if key in cache:%0A        return cache%5Bkey%5D%0A    else:%0A        with session.no_autoflush:%0A            q = session.query(cls)%0A            q = queryfunc(q, *arg, **kw)%0A            obj = q.first()%0A            if not obj:%0A                obj = constructor(*arg, **kw)%0A                session.add(obj)%0A        cache%5Bkey%5D = obj%0A        return obj%0A    %0A    %0Aclass PSD(object):%0A   %0A    @declared_attr%0A    def __tablename__(cls):%0A        return cls.__name__.lower()%0A%0A    id = Column('id', Integer, primary_key=True, autoincrement=True)%0A    cmdy_code = Column('Commodity_Code', String(7), nullable=False)%0A    ctry_code = Column('Country_Code', String(2), nullable=False)%0A    mkg_yr = Column('Market_Year', Integer, nullable=False)%0A    cal_yr = Column('Calendar_Year', Integer, nullable=False)%0A    mth = Column('Month', String(2), nullable=False)%0A    attr_id = Column('Attribute_ID', String(3), nullable=False)%0A    unit_id = Column('Unit_ID', String(2), nullable=False)%0A    val = Column('Value', Numeric(10, 2), nullable=False)%0A    #val = Column('Value', String(10), nullable=False)%0A        %0A    @classmethod%0A    def unique_hash(cls, cmdy_code, ctry_code, mkg_yr, cal_yr, mth, attr_id, unit_id, val):%0A        return cmdy_code, ctry_code, mkg_yr, cal_yr, mth, attr_id, unit_id, val%0A%0A    @classmethod%0A    def unique_filter(cls, query, cmdy_code, ctry_code, mkg_yr, cal_yr, mth, attr_id, unit_id, val):%0A        return query.filter(and_(PSD.cmdy_code == cmdy_code,%0A                                 PSD.ctry_code == ctry_code,%0A                                 PSD.mkg_yr == mkg_yr,%0A                                 PSD.cal_yr == cal_yr,%0A                                 PSD.mth == mth,%0A                                 PSD.attr_id == attr_id,%0A                                 PSD.unit_id == unit_id,%0A                                 PSD.val == val))%0A        %0A           %0Aclass psdODS(PSD, Base, UniqueMixin):%0A%0A    def __repr__(self):%0A        return '%3CpsdODS(cmdy_code=%7B%7D, ctry_code=%7B%7D%3E'.format(PSD.cmdy_code,%0A                                                                PSD.mkg_yr,%0A                                                                PSD.cal_yr,%0A                                                                PSD.mth,%0A                                                                PSD.attr_id,%0A                                                                PSD.unit_id,%0A                                                                PSD.val)%0A%0ABase.prepare(engine)%0A

Create sqlapsd.py