Automap sqlalchemy.ext.automap 自动映射数据库表结构

from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import Session
from sqlalchemy import create_engine Base = automap_base() # engine, suppose it has two tables 'user' and 'address' set up
engine = create_engine("mysql+mysqldb://wise:wise@172.31.238.141/wise?charset=utf8") # reflect the tables
Base.prepare(engine, reflect=True) # mapped classes are now created with names by default
# matching that of the table name.
User = Base.classes.user
Address = Base.classes.address session = Session(engine) # rudimentary relationships are produced
#session.add(Address(email_address="foo@bar.com", user=User(name="foo")))
#session.commit() # collection-based relationships are by default named
# "<classname>_collection"

http://www.buluo360.com/

上一篇:操作系统实现线程的几种模式 和 java创建线程的3个方式


下一篇:爬虫系列3:Requests+Xpath 爬取租房网站信息并保存本地