【问题标题】:Google App Engine null sort orderGoogle App Engine 空排序顺序
【发布时间】:2012-06-13 04:14:47
【问题描述】:

根据谷歌Documentation,空值没有排序顺序。有没有办法配置这种行为。例如,如果我按升序对整数属性进行排序,我可以将数据存储配置为最后还是先返回空值?

【问题讨论】:

    标签: google-app-engine gql


    【解决方案1】:

    您最好的选择可能是将属性保存为一个空白“”字符串,用于每个具有该属性的空值的实体。请务必在您更改的每个实体上运行 put()。

    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)。

    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)
    

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多