【问题标题】:NDB map(callback, produces_cursors=True)NDB 映射(回调,produces_cursors=True)
【发布时间】:2013-01-02 16:08:42
【问题描述】:

map() 的 Google AppEngine NDB 文档指出:

“支持所有查询选项关键字参数。”

但是,我尝试在 map() 上使用 produces_cursors=True,但没有返回光标。

map(callback, pass_batch_into_callback=None, merge_future=None, **q_options)

我想使用map(),因为我可以将回调设置为小任务。

https://developers.google.com/appengine/docs/python/ndb/queryclass#kwdargs_options

编辑 - 提供代码示例:

@ndb.tasklet
def callback(user):
    statistics = yield ndb.Key(Statistics, user.key.id()).get_async()
    raise ndb.Return(user, statistics)

result = User.query().map(callback, produces_cursors=True)

【问题讨论】:

  • 能提供sn-p的代码吗?
  • 当然@bossylobster,我已经添加了一些示例代码。
  • 确实你是对的,tasklets.MultiFuture 只返回一个列表 (code.google.com/p/appengine-ndb-experiment/source/browse/ndb/…) 而map_query 不会保留任何光标信息。
  • 嗨@Chris,在我看来,您设法让游标以某种方式工作,在我的情况下,即使没有拼写错误,也会出现问题。我已经在这里详细描述了它,stackoverflow.com/questions/21118732/… 可能你会发现一些明显被我忽略的东西。感谢您的帮助。
  • @HarshalPatil - Guido 在下面提到 map() 不返回光标,这有帮助吗?

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


【解决方案1】:

这个例子似乎有一个错字——正确的标志是produce_cursors,而不是produces_cursors

但只有在使用迭代器时才能使用游标,而不是 map()。查看异步迭代器示例;这有点工作,但您绝对可以使用它为每个结果手动创建一个 tasklet。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-28
    • 1970-01-01
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多