from sqlalchemy import MetaData, create_engine, Table, Column, String, Integer, text


class DB:
    def __init__(self):
        self.metadata = MetaData()
        # 实际运行时需配置真实数据库连接
        self.engine = create_engine( 'mysql+pymysql://用户名:密码@主机:端口/数据库名?charset=utf8mb4', echo=False)

    def connect(self):
        try:
            return self.engine.connect()
        except Exception as e:
            print('连接异常', e)

    def table(self):
        douban_movie = Table(
            'douban_movies', self.metadata,
            Column('id', Integer, primary_key=True),
            Column('m_id', String(32), unique=True),
            Column('m_title', String(32)),
            Column('m_score', String(8)),
            Column('m_rank', String(32)),
            Column('m_type', String(120)),
            Column('m_regions', String(120)),
            Column('m_release_date', String(120)),
            Column('m_actors', String(255)),
            Column('m_cover_url', String(120)),
        )
        return douban_movie



