46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
from sqlalchemy import *
|
|||
|
|
from datetime import datetime
|
||
|
|
from sqlalchemy.orm import declarative_base,sessionmaker
|
||
|
|
db_url='mysql+pymysql://root:123456@127.0.0.1:3306/ai0824?charset=utf8'
|
||
|
|
engine=create_engine(db_url , pool_size=50,echo=True)
|
||
|
|
Base=declarative_base()
|
||
|
|
class Scores(Base):
|
||
|
|
__tablename__ = 's_scores'
|
||
|
|
id=Column( Integer
|
||
|
|
, primary_key=True
|
||
|
|
,autoincrement=True
|
||
|
|
,comment='成绩编号'
|
||
|
|
)
|
||
|
|
stu_id=Column(Integer
|
||
|
|
,comment='学生编号'
|
||
|
|
, nullable=False
|
||
|
|
)
|
||
|
|
exam_seq=Column(Integer
|
||
|
|
|
||
|
|
, nullable=True
|
||
|
|
,comment='考试序次'
|
||
|
|
)
|
||
|
|
score=Column(Float
|
||
|
|
,comment='分数'
|
||
|
|
)
|
||
|
|
create_date=Column(DATETIME
|
||
|
|
, default=datetime.now
|
||
|
|
,comment='创建时间'
|
||
|
|
)
|
||
|
|
update_date=Column(DATETIME
|
||
|
|
, default=datetime.now
|
||
|
|
,onupdate=datetime.now
|
||
|
|
,comment='更新时间'
|
||
|
|
)
|
||
|
|
deleted=Column(Integer
|
||
|
|
,default=1
|
||
|
|
, comment='软删除'
|
||
|
|
)
|
||
|
|
Base.metadata.create_all(engine)
|
||
|
|
Session = sessionmaker( bind=engine
|
||
|
|
,autoflush=False
|
||
|
|
,autocommit = False
|
||
|
|
)
|
||
|
|
|
||
|
|
|