 
- Peewee教程
- Peewee - 主页
- Peewee - 概述
- Peewee - 数据库类
- Peewee - 模型
- Peewee - 野外课程
- Peewee - 插入新记录
- Peewee - 选择记录
- Peewee - 过滤器
- Peewee - 主键和复合键
- Peewee - 更新现有记录
- Peewee - 删除记录
- Peewee - 创建索引
- Peewee - 约束
- Peewee - 使用 MySQL
- Peewee - 使用 PostgreSQL
- Peewee - 动态定义数据库
- Peewee - 连接管理
- Peewee - 关系与加入
- Peewee - 子查询
- Peewee - 排序
- Peewee - 计数和聚合
- Peewee - SQL 函数
- Peewee - 检索行元组/字典
- Peewee - 用户定义的运算符
- Peewee - 原子事务
- Peewee - 数据库错误
- Peewee - 查询生成器
- Peewee - 与 Web 框架集成
- Peewee - SQLite 扩展
- Peewee - PostgreSQL 和 MySQL 扩展
- Peewee - 使用 CockroachDB
- Peewee有用资源
- Peewee - 快速指南
- Peewee - 有用的资源
- Peewee - 讨论
Peewee - 检索行元组/字典
可以在不创建模型实例的情况下迭代结果集。这可以通过使用以下方法来实现 -
- tuples() 方法。 
- dicts() 方法。 
例子
要将 SELECT 查询中的字段数据作为元组集合返回,请使用tuples()方法。
qry=Contacts.select(Contacts.City, fn.Count(Contacts.City).alias('count'))
   .group_by(Contacts.City).tuples()
lst=[]
for q in qry:
   lst.append(q)
print (lst)
输出
输出如下 -
[
   ('Chennai', 1), 
   ('Delhi', 2), 
   ('Indore', 1), 
   ('Mumbai', 1), 
   ('Nagpur', 1), 
   ('Nasik', 3), 
   ('Pune', 1)
]
例子
获取字典对象的集合 -
qs=Brand.select().join(Item).dicts() lst=[] for q in qs: lst.append(q) print (lst)
输出
输出如下:
[
   {'id': 1, 'brandname': 'Dell', 'item': 1}, 
   {'id': 2, 'brandname': 'Epson', 'item': 2}, 
   {'id': 3, 'brandname': 'HP', 'item': 1}, 
   {'id': 4, 'brandname': 'iBall', 'item': 3},
   {'id': 5, 'brandname': 'Sharp', 'item': 2}
]