peewee快速使用
来源:互联网 发布:软件行业平均利润率 编辑:程序博客网 时间:2024/06/05 09:51
示例
模型定义和Django、SQLAlchemy类似
连接到数据库并创建表格和添加数据
查询
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# A simple query selecting a user.
User.get(User.username=='charles')
# Get tweets created by one of several users. The "<<" operator
# corresponds to the SQL "IN" operator.
usernames=['charlie','huey','mickey']
users=User.select().where(User.username<<usernames)
tweets=Tweet.select().where(Tweet.user<<users)
# We could accomplish the same using a JOIN:
tweets=(Tweet
.select()
.join(User)
.where(User.username<<usernames))
# How many tweets were published today?
tweets_today=(Tweet
.select()
.where(
(Tweet.created_date>=datetime.date.today())&
(Tweet.is_published==True))
.count())
# Paginate the user table and show me page 3 (users 41-60).
User.select().order_by(User.username).paginate(3,20)
# Order users by the number of tweets they've created:
tweet_ct=fn.Count(Tweet.id)
users=(User
.select(User,tweet_ct.alias('ct'))
.join(Tweet,JOIN.LEFT_OUTER)
.group_by(User)
.order_by(tweet_ct.desc()))
# Do an atomic update
Counter.update(count=Counter.count+1).where(
Counter.url==request.url)
官方网站:http://docs.peewee-orm.com/en/latest/index.html#
开源地址:https://github.com/coleifer/peewee
开源地址:https://github.com/coleifer/peewee
阅读全文
0 0
- peewee快速使用
- peewee
- peewee
- Peewee中文文档【二】:快速开始
- python使用peewee实现mysql数据操作
- Python中的ORM使用之peewee
- Python的ORM框架Peewee使用入门(一)
- Python的ORM框架Peewee使用入门(二)
- Python的ORM框架Peewee使用入门(三)
- python ORM 模块peewee(二): 数据库使用的基本流程
- 使用peewee将数据库从mysql导入mongodb
- peewee入门
- python轻量级ORM---peewee
- peewee 对象clone函数
- peewee 动态定义数据库
- peewee 中文翻译文档
- peewee 一个轻量级的ORM
- Peewee中文文档【五】:贡献
- (jfinal)数据库添加内容后,自动生成model下的Java文件方法
- 代理模式
- tomcat 端口被占用
- 几种主流编程语言的优势与不足
- 第二章 信息的表示和处理
- peewee快速使用
- Android Studio 中的maven仓库使用
- 【Java并发编程】并发编程大合集
- JS类型检测-笔记
- ajax请求总是不成功?浏览器的同源策略和跨域问题详解
- Mysql,replace函数,in函数用法
- iskindofclass和ismemberofclass的区别
- Centos 6.9 编译install gcc-4.9.4
- Linux学习第二十三篇--数据流重导向