peewee 介绍
peewee 是一个轻量级的 python ORM 库。内建对 sqlite、MysqL 和 Postgresql 的支持。支持 Python 2.6+ 和
Python 3.2+。
pip 安装:pip install peewee
示例代码:
from peewee import * db = sqliteDatabase('people.db') class Person(Model): name = CharField() birthday = DateField() is_relative = BooleanField() class Meta: database = db # This model uses the "people.db" database. >>> from datetime import date >>> uncle_bob = Person(name='Bob', birthday=date(1960, 1, 15), is_relative=True) >>> uncle_bob.save() # bob is Now stored in the database 1 >>> grandma = Person.select().where(Person.name == 'Grandma L.').get() >>> grandma = Person.get(Person.name == 'Grandma L.') >>> for person in Person.select(): ... print person.name, person.is_relative ... Bob True Grandma L. True Herb False
高级用法:
import peewee from peewee import * db = MysqLDatabase('jonhydb', user='john',passwd='megajonhy') class Book(peewee.Model): author = peewee.CharField() title = peewee.TextField() class Meta: database = db Book.create_table() book = Book(author="me", title='peewee is cool') book.save() for book in Book.filter(author="me"): print book.title peewee is cool
peewee 官网
http://peewee.readthedocs.org/
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。