Skip to content
Find file
554ba4a Server Changed the import script.
67 lines (51 sloc) 2.1 KB
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker, relation, backref
import sqlalchemy
from database_settings import CONNECTION_STRING
except ImportError:
CONNECTION_STRING = "sqlite:///imdbapi.db"
Base = declarative_base()
class Show(Base):
__tablename__ = 'shows'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
name = sqlalchemy.Column(sqlalchemy.Unicode(200))
year = sqlalchemy.Column(sqlalchemy.Integer)
def __init__(self, name, year): = name
self.year = year
def __repr__(self):
return "<Show('%s','%s')>" % (, self.year)
sqlalchemy.Index('idx_show_name_year',, Show.year)
class Episode(Base):
__tablename__ = 'episodes'
id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True)
show_id = sqlalchemy.Column(sqlalchemy.Integer, sqlalchemy.ForeignKey(''), index=True)
name = sqlalchemy.Column(sqlalchemy.Unicode(200), index=True)
season = sqlalchemy.Column(sqlalchemy.Integer)
number = sqlalchemy.Column(sqlalchemy.Integer)
show = relation(Show, backref='episodes', order_by=id)
def __init__(self, show, name, season, number): = show = name
self.season = season
self.number = number
def __repr__(self):
return "<Episode('%s.%s','%s')>" % (self.season, self.number,
class Stats(Base):
__tablename__ = 'stats'
key = sqlalchemy.Column(sqlalchemy.Unicode(200), index=True, primary_key=True)
value = sqlalchemy.Column(sqlalchemy.Integer)
def __init__(self, key, value):
self.key = key
self.value = value
def __repr__(self):
return "<Stats('%s','%s')>" % (self.key, self.value)
def init_db(transactional=False):
engine = sqlalchemy.create_engine(CONNECTION_STRING)
Session = sessionmaker(bind=engine, transactional=transactional)
session = Session()
return session
if __name__ == "__main__":
Jump to Line
Something went wrong with that request. Please try again.