from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, TIMESTAMP, text, JSON

from ....common.sqlSession import to_dict

Base = declarative_base()
Base.to_dict = to_dict


class CreateInfo(Base):
    __tablename__ = 'create_data_info'
    create_data_info_id = Column(String(120), primary_key=True, comment='传入参数的id')
    create_data_detail_id = Column(String(120), unique=True, comment='基础信息的id')
    class_name = Column(String(120), unique=True, comment='类名称')
    method_name = Column(String(120), unique=True, comment='方法名称')
    request_parameter = Column(JSON, unique=True, comment='请求参数')
    del_flag = Column(Integer, unique=True, comment='0：未删除；1：已删除')
    created_time = Column(TIMESTAMP, server_default=text('CURRENT_TIMESTAMP'), comment='创建时间')
    modified_time = Column(TIMESTAMP, server_default=text('CURRENT_TIMESTAMP'),
                           server_onupdate=text('CURRENT_TIMESTAMP'), comment='更新时间')

    def __repr__(self):
        return '<create_data_info %r>' % self.create_data_info_id
