peewee 轻量级的python ORM

我要开发同款
匿名用户2012年04月27日
112阅读

技术信息

授权协议
MIT

作品详情

peewee是一个轻量级的pythoORM库。内建对SQLite、MySQL和PostgreSQL的支持。支持Pytho2.6+和Pytho3.2+。

pip安装:pipistallpeewee

示例代码:

from peewee import *db = SqliteDatabase('people.db')class Perso(Model):    ame = CharField()    birthday = DateField()    is_relative = BooleaField()    class Meta:        database = db # This model uses the "people.db" database.>>> from datetime import date>>> ucle_bob = Perso(ame='Bob', birthday=date(1960, 1, 15), is_relative=True)>>> ucle_bob.save() # bob is ow stored i the database1>>> gradma = Perso.select().where(Perso.ame == 'Gradma L.').get()>>> gradma = Perso.get(Perso.ame == 'Gradma L.')>>> for perso i Perso.select():...     prit perso.ame, perso.is_relative...Bob TrueGradma L. TrueHerb False

高级用法:

import peeweefrom peewee import *db = MySQLDatabase('johydb', user='joh',passwd='megajohy')class Book(peewee.Model):    author = peewee.CharField()    title = peewee.TextField()    class Meta:        database = dbBook.create_table()book = Book(author="me", title='Peewee is cool')book.save()for book i Book.filter(author="me"):    prit book.titlePeewee is cool

功能介绍

peewee 是一个轻量级的 python ORM 库。内建对 SQLite、MySQL 和 PostgreSQL 的支持。支持 Python 2.6+ 和 Python 3.2+。 pip 安...

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论