[英]How to get peewee result length
I use peewee orm in python. 我在python中使用peewee orm。
I have a query that : 我有一个查询:
userOrganizations = (UserOrganization
.select(UserOrganization,Organization)
.join(Organization)
.where(UserOrganization.user==user.user_id)
.aggregate_rows()
)
I want to get length of userOrganizations variable. 我想得到userOrganizations变量的长度。 Is there any method like userOrganizations.length() ? 有没有像userOrganizations.length()这样的方法?
According to the peewee documentation you can use the count()
function, ie: 根据peewee文档,您可以使用count()
函数,即:
userOrganizations.count()
If you're worried about maybe running extra DB queries, you can convert your result to a list and get the length, like: 如果您担心可能会运行额外的数据库查询,您可以将结果转换为列表并获取长度,例如:
len(list(userOrganizations))
Source for second technique: this question . 第二种技术的来源: 这个问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.