sqlalchemy创建表

2019-03-13  本文已影响0人  ___大鱼___

#from sqlalchemy import Column,Integer, String, create_engine
from sqlalchemy import *
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.elements import BinaryExpression
from SqlData.Repository import *
import types

# 创建实体对象基类
Base = declarative_base()

#用户实体类
class EntityUser(Base):
    __tablename__ = "oc_user"

    user_id = Column(String(50),primary_key=True)
    user_name = Column(String(50))
    user_pwd = Column(String(50))
    real_name = Column(String(50))
    user_sex = Column(Integer)

#试验信息实体类
class EntityExperiment(Base):
    __tablename__ = "oc_experiment"

    experiment_id = Column(String(50),primary_key=True)
    experiment_user_id = Column(String(50))
    experiment_user_name = Column(String(50))
    experiment_type = Column(Integer)
    material_name = Column(String(50))
    set_temp = Column(Float)
    description = Column(String(50))


#试验记录信息实体类
class EntityExperimentRecord(Base):
    __tablename__ = "oc_experiment_record"

    record_id = Column(String(50),primary_key=True)
    experiment_step_id = Column(String(50))
    experiment_id = Column(String(50))
    temp_value = Column(Float)



if __name__ == '__main__':
    engine = create_engine('sqlite:///E:\DB\Photolysis.db', connect_args={'check_same_thread': False})
    Base.metadata.create_all(engine)


上一篇下一篇

猜你喜欢

热点阅读