# -*- coding:utf-8 -*-
# Date: 2018/10/16 10:30
from datetime import datetime
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.dialects.mysql import INTEGER
from sqlalchemy import String, Column, Integer, TIMESTAMP, Date, text, DateTime, Boolean
COMPANY_LINK_INFO = 'mysql+pymysql://{}:{}@{}/{}?charset={}'.format(USER_NAME, PASS_WORD,IP, DATABASE, CHARSET)
engine = create_engine(COMPANY_LINK_INFO, max_overflow=5, pool_recycle=3600, pool_pre_ping=True)
Session = sessionmaker(bind=engine)
Base = declarative_base()
class ScadaPage(Base):
__tablename__ = 'company_info'
__table_args__ = {
'mysql_engine': 'InnoDB',
'mysql_charset': 'utf8'
}
id = Column(Integer(), primary_key=True, autoincrement=True)
name = Column(String(30), nullable=False, comment='公司名称')
link = Column(String(50), nullable=False, comment='公司链接')
tax_num = Column(Integer(), nullable=False,default='-', comment='税号')
address= Column(String(50), nullable=False, default='-',comment='地址')
phone_num = Column(Integer(), nullable=False,default='-', comment='电话号码')
bank_name = Column(String(20), nullable=False,default='-', comment='开户银行')
bank_count = Column(Integer(), nullable=False, default='-',comment='银行账户')
add_time = Column(DateTime, nullable=False, default=datetime.now(), server_default='1970-01-01 00:00:00',comment='创建时间') #server_default 是创建表时,统一写入默认值,default是写入数据为空时,采用默认值
update_time = Column(TIMESTAMP, nullable=False, server_default=text('NOW()'), comment=u'更新时间')
def __init__(self, **kwargs):
super(ScadaPage, self).__init__(**kwargs)
def __repr__(self):
return ''.format(self.id)