Google App Engine空排序顺序 [英] Google App Engine null sort order

查看:113
本文介绍了Google App Engine空排序顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Google的文档,空值没有排序顺序。有没有什么办法来配置这种行为。例如,如果我按升序对整数属性进行排序,我可以将数据存储配置为最后还是第一个返回空值?

According to Googles Documentation, null values have no sort order. Is there any way to configure this behavior. For instance, if I am sorting an integer property in ascending order, can I configure the datastore to return null values last or first?

推荐答案

您最好的选择可能是将该属性保存为每个实体的空白字符串,该实体对该属性具有空值。

Your best bet may be to save the property as a blank "" string for each entity that has a null value for that property. Be sure to run put() on each entity that you alter.

employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None: # Null value property
        employee.hobbies = ""
        employee.put()

当然,这不是执行此任务的最有效方式。您可能希望创建一个列表对象,如batch_put_list,并将每个员工对象附加到列表中。然后执行db.put(batch_put_list)。

Of course, this is not the most efficient way to perform this task. You may want to create a list object, like "batch_put_list," and append each employee object into the list. Then, perform a db.put(batch_put_list).

batch_put_list = []
employees = Employee.all().fetch(50)
for employee in employees:
    if employee.hobbies is None:
        employee.hobbies = ""
        batch_put_list.append(employee)
db.put(batch_put_list)

希望这有帮助。

这篇关于Google App Engine空排序顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆