NDB 地图(回调,produces_cursors=True) [英] NDB map(callback, produces_cursors=True)
问题描述
map() 的 Google AppEngine NDB 文档指出:
The Google AppEngine NDB Documentation for map() states that:
支持所有查询选项关键字参数."
"All query options keyword arguments are supported."
但是,我尝试在 map()
上使用 produces_cursors=True
并且我没有得到光标.
However, I have tried to use produces_cursors=True
on map()
and I'm not getting a cursor back.
map(callback, pass_batch_into_callback=None, merge_future=None, **q_options)
我想使用 map()
因为我可以将回调设置为 tasklet.
I'd like to use map()
as I can set the callback to a tasklet.
https://developers.google.com/appengine/docs/python/ndb/queryclass#kwdargs_options
编辑 - 提供代码示例:
Edit - Providing code sample:
@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)
推荐答案
这个例子似乎有一个错字——正确的标志是 produce_cursors
,而不是 produces_cursors
.
The example seems to have a typo -- the correct flag is produce_cursors
, not produces_cursors
.
但是游标仅在您使用迭代器时才可用,而不是 map()
.查看异步迭代器示例;这是一点点工作,但您绝对可以使用它为每个结果手动创建一个 tasklet.
But cursors are only made available when you use an iterator, not with map()
. Check out the async iterators example; it's a little bit of work but you can definitely use it to manually create a tasklet for each result.
这篇关于NDB 地图(回调,produces_cursors=True)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!