Python’s SQLAlchemy vs Other ORMs[转发 5] PonyORM
PonyORM
PonyORM allows you to query the database using Python generators. These generators are translated into SQL and the results are automatically mapped into Python objects. Writing queries as Python generators makes it easy for programmers to quickly construct certain queries.
For example, let's use PonyORM to query the previous Person and Address models in a SQLite database.
>>> from pony.orm import Database, Required, Set
>>>
>>> db = Database('sqlite', ':memory:')
>>>
>>>
>>> class Person(db.Entity):
... name = Required(unicode)
... addresses = Set("Address")
...
>>>
>>> class Address(db.Entity):
... address = Required(unicode)
... person = Required(Person)
...
>>> db.generate_mapping(create_tables=True)
Now we have a SQLite database in memory and two tables mapped to the db object, we can insert two objects into the database.
>>> p = Person(name="person")
>>> a = Address(address="address", person=p)
>>> db.commit()
The call db.commit() actually commits the new objects p and a into the database. Now we can query the database using the generator syntax.
>>> from pony.orm import select
>>> select(p for p in Person if p.name == "person")[:]
[Person[1]]
>>> select(p for p in Person if p.name == "person")[:][0].name
u'person'
>>> select(a for a in Address if a.person == p)[:]
[Address[1]]
>>> select(a for a in Address if a.person == p)[:][0].address
u'address'
Python’s SQLAlchemy vs Other ORMs[转发 5] PonyORM的更多相关文章
- Python’s SQLAlchemy vs Other ORMs[转发 7] 比较结论
Comparison Between Python ORMs For each Python ORM presented in this article, we are going to list t ...
- Python’s SQLAlchemy vs Other ORMs[转发 6]SQLAlchemy
SQLAlchemy SQLAlchemy is an open source SQL toolkit and ORM for the Python programming language rele ...
- Python’s SQLAlchemy vs Other ORMs[转发 0]
原文地址:http://pythoncentral.io/sqlalchemy-vs-orms/ Overview of Python ORMs As a wonderful language, Py ...
- Python’s SQLAlchemy vs Other ORMs[转发 3]Django's ORM
Django's ORM Django is a free and open source web application framework whose ORM is built tightly i ...
- Python’s SQLAlchemy vs Other ORMs[转发 2]Storm
Storm Storm is a Python ORM that maps objects between one or more databases and Python. It allows de ...
- Python’s SQLAlchemy vs Other ORMs[转发 1]SQLObject
SQLObject SQLObject is a Python ORM that maps objects between a SQL database and Python. It is becom ...
- Python’s SQLAlchemy vs Other ORMs[转发 4]peewee
peewee peewee is a small, expressive ORM. Compared to other ORMs, peewee focuses on the principal of ...
- 基于Python的SQLAlchemy的操作
安装 在Python使用SQLAlchemy的首要前提是安装相应的模块,当然作为python的优势,可以到python安装目录下的scripts下,同时按住shift+加上鼠标左键,从而在菜单中打开命 ...
- SQLAlchemy(1) -- Python的SQLAlchemy和ORM
Python的SQLAlchemy和ORM(object-relational mapping:对象关系映射) web编程中有一项常规任务就是创建一个有效的后台数据库.以前,程序员是通过写sql语句, ...
随机推荐
- eclipse中配置tomcat
配置eclipse中的tomcat非常简单,之前以为windows下和mac中可能会不一样,但是经过配置发现是一样的: 下面就是在eclipse中简单的配置tomcat如下(mac和windows中都 ...
- html5中的clip
定义和用法 clip() 方法从原始画布中剪切任意形状和尺寸. 提示:一旦剪切了某个区域,则所有之后的绘图都会被限制在被剪切的区域内(不能访问画布上的其他区域).您也可以在使用 clip() 方法前通 ...
- C#实现执行多条SQl语句,实现数据库事务
C#实现执行多条SQl语句,实现数据库事务 在数据库中使用事务的好处,相信大家都有听过银行存款的交易作为事务的一个例子.事务处理可以确保除非事务性单元内的所有操作都成功完成,否则不会永久更新面向数据的 ...
- Web应用程序项目以配置使用IIS。未找到Web服务器
解决办法 右键编辑该Web项目的csproj文件 把UserIIS改为False.或者在IIS服务器里面配置一个IISUrl里面的地址 如图
- VIM 中鼠标选择不选中行号
VIM 中鼠标选择不选中行号 在Vim中,我们一般会使用 :set nu 打开行号开关. 但是打开行号后,有个弊端,那就是在用鼠标进行选择的时候,会将前面的行号也一起进行拷贝了.但是在gVim中进行选 ...
- 利用angular与后台的交互
记录的世界是强大的,不管天南海北还是五湖四海,如果利用angular js与后台的交互.angular js 在api上称为是http服务: 下面咱给一个简单的代码看看:简单的利用后台与前端的tab切 ...
- [Python]实现XMPP协议即时通讯发送消息功能
#-*- coding: utf-8 -*- __author__ = 'tsbc' import xmpp import time #注意帐号信息,必须加@域名格式 from_user = 'che ...
- SPOJ 375. Query on a tree (树链剖分)
Query on a tree Time Limit: 5000ms Memory Limit: 262144KB This problem will be judged on SPOJ. Ori ...
- Web的Ajax应用开发模式(三)——Ajax的开发
Ajax是XMLHttpRequest对象和JavaScript.CSS.HTML.DOM等多种技术的结合. 此处重点强调XMLHttpRequest的以下特点,所以测试人员在测试到WEB的Ajax应 ...
- ArrayList代码示例
package com.shushine.framework.第七章Java标准类库;import java.util.ArrayList;/** * * <p> * 描述该类情况 {@l ...