sqlite-sqlalchemy

1. create table

from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class Corp(Base):
    __tablename__ = 'corp'  #  企业

    id = Column(String(20), primary_key=True)
    name = Column(String(100))                 # 公司名称
    href = Column(String(100))                 # 网站地址
    belong = Column(String(100))               # 所属网站
    update = Column(String(100))               # 采集时间
    author = Column(String(100))               # 采集作者
    flag = Column(String(100))                 # 采集标志位

engine = create_engine('sqlite:///./test.db')
Base.metadata.create_all(engine)

DBSession = sessionmaker(bind=engine)

session = DBSession()

#new_user = User(id='5', name='Bob')
#session.add(new_user)
session.commit()
session.close()

 

posted @ 2018-04-08 14:54  yugengde  阅读(460)  评论(0编辑  收藏  举报