NDB映射(回调,produce_cursors = True)

Chr*_*ris 5 python google-app-engine app-engine-ndb

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

"支持所有查询选项关键字参数."

但是,我试图使用produces_cursors=Trueon map()并且我没有得到光标.

map(callback, pass_batch_into_callback=None, merge_future=None, **q_options)
Run Code Online (Sandbox Code Playgroud)

我想使用,map()因为我可以将回调设置为tasklet.

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)
Run Code Online (Sandbox Code Playgroud)

Gui*_*sum 4

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

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