peewee 正在参加 2021 年度 OSC 中国开源项目评选,请投票支持!
peewee 在 2021 年度 OSC 中国开源项目评选 中已获得 {{ projectVoteCount }} 票,请投票支持!
2021 年度 OSC 中国开源项目评选 正在火热进行中,快来投票支持你喜欢的开源项目!
2021 年度 OSC 中国开源项目评选 >>> 中场回顾
peewee 获得 2021 年度 OSC 中国开源项目评选「最佳人气项目」 !
授权协议 MIT
开发语言 Python
操作系统 跨平台
软件类型 开源软件
开源组织
地区 不详
投 递 者 易界灰
适用人群 未知
收录时间 2012-04-27

软件简介

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
展开阅读全文

代码

评论

点击加入讨论🔥(2)
发表于开发技能专区
2018/04/23 07:26

Peewee 3.2.5 发布,轻量级 Python ORM 库

Peewee 3.2.5 已发布,Peewee 是一个轻量级的 python ORM 库,内置对 SQLite、MySQL 和 PostgreSQL 的支持。支持 Python 2.7+ 和 Python 3.4+。 更新内容: 新增 ValuesList ,示例如下: data = [(1, 'first'), (2, 'second')] vl = ValuesList(data, columns=('idx', 'name')) query = (vl          .select(vl.c.idx, vl.c.name)          .order_by(vl.c.idx)) # Yields: # SELEC...

1
5
没有更多内容
加载失败,请刷新页面
点击加载更多
加载中
下一页
发表了博客
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
发表了问答
{{o.pubDate | formatDate}}

{{formatAllHtml(o.title)}}

{{parseInt(o.replyCount) | bigNumberTransform}}
{{parseInt(o.viewCount) | bigNumberTransform}}
没有更多内容
暂无内容
暂无内容
2 评论
30 收藏
分享
OSCHINA
登录后可查看更多优质内容
返回顶部
顶部