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的更多相关文章

  1. 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 ...

  2. Python’s SQLAlchemy vs Other ORMs[转发 6]SQLAlchemy

    SQLAlchemy SQLAlchemy is an open source SQL toolkit and ORM for the Python programming language rele ...

  3. Python’s SQLAlchemy vs Other ORMs[转发 0]

    原文地址:http://pythoncentral.io/sqlalchemy-vs-orms/ Overview of Python ORMs As a wonderful language, Py ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Python’s SQLAlchemy vs Other ORMs[转发 5] PonyORM

    PonyORM PonyORM allows you to query the database using Python generators. These generators are trans ...

  8. 基于Python的SQLAlchemy的操作

    安装 在Python使用SQLAlchemy的首要前提是安装相应的模块,当然作为python的优势,可以到python安装目录下的scripts下,同时按住shift+加上鼠标左键,从而在菜单中打开命 ...

  9. SQLAlchemy(1) -- Python的SQLAlchemy和ORM

    Python的SQLAlchemy和ORM(object-relational mapping:对象关系映射) web编程中有一项常规任务就是创建一个有效的后台数据库.以前,程序员是通过写sql语句, ...

随机推荐

  1. 从零开始调用一个手机号归属地查询API

    自从过上程序员的生活,身边总是或多或少的提及一些API(应用程序接口),网上各种入门教程.实例大把大把,有的只是贴上部分代码,也不给注释, 写Demo的时候连编译都无法通过.下面我从小白开始来介绍下调 ...

  2. VS2012使用中容易出现的小问题(长期更新,错多少记多少)

    1:各种属性之间一定要有空格!比如id 和 runat中间一定要有,在编译系统里虽然也能显示红色,但是...调试的时候一定会报错!而且这样的错误很难发现(相信我曾经花了半个小时才找出问题) 2:在类中 ...

  3. AOP报错:Caused by: java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut

    Spring3.x升级4.x时遇到的,JDK版本1.7 aspectj版本问题,1.6.x升级到1.7.x,解决!

  4. RemotelyAnywhere 11.0.2716 SERVER EDITION 绿色破解安装版

    RemotelyAnywhere是一个小巧的,利用浏览器进行远程控制的小程序.只要在服务器端安装该软件,然后你就可以通过任何一个支持 Java 的浏览器对远程计算机进行控制了.通过它,你可以管理远程计 ...

  5. Xcode 8 Swift 类似插件方法

    Xcode8 Swift使用技巧 1 option + cmd + / 可以弹出注释 2 color 然后加 enter 可以弹出颜色选择 3    #FIXME:  警告 4   #MARK: 备注 ...

  6. java 垃圾回收

    转自:http://www.360doc.com/content/13/0305/10/15643_269388816.shtml

  7. [bzoj 3732] Network (Kruskal重构树)

    kruskal重构树 Description 给你N个点的无向图 (1 <= N <= 15,000),记为:1-N. 图中有M条边 (1 <= M <= 30,000) ,第 ...

  8. Spark HA实战

    Spark HA需要安装zookeeper,推荐稳定版3.4.6. 1.下载zookeeper3.4.6,2.配置环境变量3.创建data logs4.vi conf/zoo.cfg5 data目录中 ...

  9. 1.Dotnet Core安装

    DtnetCore1.0.1的安装包我以上传至百度网盘,里面有安装教程. http://pan.baidu.com/s/1c2iLNNE 如果安装不上,请留言,我会在第一时间回复你. 不需要挂VPN.

  10. UVA 11520 填充正方形

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...