欢迎各位小哥哥小姐姐阅读本的文章,对大家学习有帮助,请点赞加关注哦!!!!!!!!!!
您的点赞和关注将是我持续更新的动力呢.^v^
有不懂的问题可以私聊我哦!
目前最知名的Python ORM是SQLAlchemy和SQLObject。那我将分别给出这两种例子,由于设计哲学的不同,这两种ORM也会存在一些区别。
不过!一旦你学会了其中一种,迁移到其他ORM就会变得更加容易。
其他一些 Python ORM还包括:
- Storm、
- PyDO/PyDO2、
- PDO、Dejavu、
- Durus、
- QLime和 ForgetSQL。
基于 Web 的大型系统也会包含它们自己的 ORM 组件,如 WebWare
MiddieKit和Django 的数据库 API。值得提醒的是,知名的 ORM并不意味着适合于你的
应用。尽管这些ORM并不在我们的讨论范围内,但这不意味着这些ORM就不适用于你
的应用。
安装
由于 SQLAIchemy和SQLObject都不在标准库当中,因此需要手动下载以及安装它们(通常可以使用 easy install或pip工具比较方便地安装)。
上面讲的所有包都支持 Python2,只有SQLAlchemy,SQLite 和MySQL Connector/Python 适配器还支持Python 3。 sqlite3包在 Python 2.5+或Python 3.x中已经作为标准库的一部分了,所以除非你使用的是2.4或更老的版本,否则不需要做任何其他事情。
如果你的计算机中只安装了Python3,那么你需要先获取Distribute(包含了 easy_install)。你需要一个 Web 浏览器(或者curl命令)来下载安装文件),然后使用easy install 获取SQLAlchemy。
下面是在一台Windows PC上的整个过程示意:
C:WINDOWSTemp>C:Python32python distribute_setup.PY
Extracting in c:docume~1wesleylocals~1empmp8mcddr
Now working in c:docume~1wesleylocals~1empmp8mcddrdistribute-
0.6.21
Installing Distribute
warning:no files found matching 'Makefile' under directory'docs'
warning:no files found matching 'indexsidebar.html'under directory
'docs'
creating build
creating buildsrc
Installing easy_install-3.2.exe script toC:python32Scripts
noriv9
Installedc:python32libsite-packagesdistribute-0.6.21-py3.2.egg
Processing dependencies for distribute==0.6.21
Finished processing dependencies for distribute==0.6.21
After install bootstrap.
CreatingC:python32Libsite-packagessetuptools-0.6c11-py3.2.egg-info
Creating C:python32Libsite-packagessetuptools.pth
C:WINDOWSTemp>
C:WINDOWSTemp>C:Python32Scriptseasy_install sqlalchemy
Searching for sqlalchemy
Reading http://pypi.python.org/simple/sqlalchemy/
Reading http://www.sqlalchemy.org
Best match:SQLAlchemy 0.7.2
Downloading http://pypi.python.org/packages/source/S/SQLAlchemy/
SQLAlchemy-0.7.2.tar.gz#md5=b84a26ae2e5de6f518706929bf8f72
Adding sqlalchemy 0.7.2 to easy-install.pth file
Installed c:python32libsite-packagessqlalchemy-0.7.2-py3.2.egg
Processing dependencies for sqlalchemy
Finished processing dependencies for sqlalchemy