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 minimalism where the API is simple and the library is easy to use and understand.
pip install peewee
Downloading/unpacking peewee
Downloading peewee-2.1.7.tar.gz (1.1MB): 1.1MB downloaded
Running setup.py egg_info for package peewee Installing collected packages: peewee
Running setup.py install for peewee
changing mode of build/scripts-2.7/pwiz.py from 644 to 755 changing mode of /Users/xiaonuogantan/python2-workspace/bin/pwiz.py to 755
Successfully installed peewee
Cleaning up...
To create a database model mapping, we implement a Person
class and an Address
class that map to the corresponding database tables.
>>> from peewee import SqliteDatabase, CharField, ForeignKeyField, Model
>>>
>>> db = SqliteDatabase(':memory:')
>>>
>>> class Person(Model):
... name = CharField()
...
... class Meta:
... database = db
...
>>>
>>> class Address(Model):
... address = CharField()
... person = ForeignKeyField(Person)
...
... class Meta:
... database = db
...
>>> Person.create_table()
>>> Address.create_table()
To insert objects into the database, we instantiate the objects and call their save()
methods. From object creation point of view, peewee
is very similar to Django.
>>> p = Person(name='person')
>>> p.save()
>>> a = Address(address='address', person=p)
>>> a.save()
To get or retrieve the objects from the database, we select
the objects from their respective classes.
>>> person = Person.select().where(Person.name == 'person').get()
>>> person
>>>
>>> print '%r, %r' % (person.id, person.name)
1, u'person'
>>> address = Address.select().where(Address.person == person).get()
>>> print '%r, %r' % (address.id, address.address)
1, u'address'
Python’s SQLAlchemy vs Other ORMs[转发 4]peewee的更多相关文章
- 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[转发 5] PonyORM
PonyORM PonyORM allows you to query the database using Python generators. These generators are trans ...
- 基于Python的SQLAlchemy的操作
安装 在Python使用SQLAlchemy的首要前提是安装相应的模块,当然作为python的优势,可以到python安装目录下的scripts下,同时按住shift+加上鼠标左键,从而在菜单中打开命 ...
- SQLAlchemy(1) -- Python的SQLAlchemy和ORM
Python的SQLAlchemy和ORM(object-relational mapping:对象关系映射) web编程中有一项常规任务就是创建一个有效的后台数据库.以前,程序员是通过写sql语句, ...
随机推荐
- Redmine自定义字段增多后会变慢
问题: 在Redmine部署使用后,发现更新事务时速度慢,进行了相关试验,去掉了可能影响速度的插件,仍然很慢.以下为对比试验: 1.包含12个自定义字段的项目,更新用时2136ms,记录如下: Sta ...
- Java数据结构之表的增删对比---ArrayList与LinkedList之一
一.Java_Collections表的实现 与c不同Java已经实现并封装了现成的表数据结构,顺序表以及链表. 1.ArrayList是基于数组的实现,因此具有的特点是:1.有索引值方便查找,对于g ...
- mybatis,Spring等工具对xml文件正确性的验证
我们知道mybatis或者spring都是使用xml文件作为配置文件,配置文件的格式都是定义在叫做.dtd或者.xsd文件中的,当工具在解析用户自己定义的xml文件的时候,如何才能知道用户自定义的文件 ...
- 转:Log4j使用
转:https://my.oschina.net/kkrgwbj/blog/638780 日志是应用软件中不可缺少的部分,Apache的开源项目log4j是一个功能强大的日志组件,提供方便的日志记录. ...
- NodeJS 调试工具(node-inspector)
node-inspector是基于Chrome的调试工具. 安装: npm install -g node-inspector 1.启动node-inspector来监听node.js的debug调试 ...
- input失去隐藏光标(移动端)
<input type="text" readonly name='lbinput' onfocus="lbinput.blur()">
- Bash:-:-获取未来40天的日期
<---获取40天日期数组---> ..};do echo "$(date --date=''${i}' days ago' "+%Y%m%d")" ...
- Oracle RAC安装部署文档
1. 部署环境步骤 1.1 软件环境 操作系统:CentOS release 6.5(推荐使用5.*的系统)192.168.1.151 racnode1 192.168.1.152 ...
- python字符串方法的简单使用
学习python字符串方法的使用,对书中列举的每种方法都做一个试用,将结果记录,方便以后查询. (1) s.capitalize() ;功能:返回字符串的的副本,并将首字母大写.使用如下: >& ...
- 同一界面放两个TTIWDBAdvWebGrid的问题(delphi IW TMS)
同一个界面放了两个 TTIWDBAdvWebGrid 时,操作一个表,另一个的也跟着一起更改了,后查看网页生成的DIV,发现ID相同. 后查,有一个ID属性,更改后解决问题.