【问题标题】:Is it possible to tell whether an NDB cursor has been reversed?是否可以判断 NDB 游标是否已反转?
【发布时间】:2013-02-28 12:24:35
【问题描述】:

从 GAE 文档中,可以通过以下方式制作反向光标:

rev_cursor = cursor.reversed()

我正在寻找类似cursor.is_reversed() 的东西,它会返回光标是否被反转。

存在吗?

【问题讨论】:

    标签: python google-app-engine google-cloud-datastore app-engine-ndb


    【解决方案1】:

    不,不会保留此类信息。 .reversed() 调用只是返回一个位置相反的新光标:

    def reversed(self):
        """Creates a cursor for use in a query with a reversed sort order."""
        for pos in self.__compiled_cursor.position_list():
            if pos.has_start_key():
                raise datastore_errors.BadRequestError('Cursor cannot be reversed.')
    
        rev_pb = datastore_pb.CompiledCursor()
        rev_pb.CopyFrom(self.__compiled_cursor)
        for pos in rev_pb.position_list():
            pos.set_start_inclusive(not pos.start_inclusive())
        return Cursor(_cursor_pb=rev_pb)
    

    (为了便于阅读,源代码重新缩进了 4 个空格)。

    【讨论】:

      猜你喜欢
      • 2011-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-04
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多