VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • Python 操作 MySQL 的5种方式(3)

官方文档:http://docs.peewee-orm.com/en/latest/peewee/installation.html

 

5、SQLAlchemy

如果想找一种既支持原生 SQL,又支持 ORM 的工具,那么 SQLAlchemy 是最好的选择,它非常接近 Java 中的 Hibernate 框架。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy_declarative import Address, Base, Person
class Address(Base):
    __tablename__ = 'address'
    id = Column(Integer, primary_key=True)
    street_name = Column(String(250))
engine = create_engine('sqlite:///sqlalchemy_example.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
# Insert a Person in the person table
new_person = Person(name='new person')
session.add(new_person)
session.commit()

现在差不多搞明白了这几种数据库驱动的优劣,接下来你就可以选择其中的一个进行系统的学习再把它应用到项目中去了,祝你学习开心,不懂的可以咨询我哈。

 

相关教程