NDB映射(callback,produce_cursors = True) [英] NDB map(callback, produces_cursors=True)

查看:100
本文介绍了NDB映射(callback,produce_cursors = True)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

map()的Google AppEngine NDB文档声明:

The Google AppEngine NDB Documentation for map() states that:


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

"All query options keyword arguments are supported."

但是,我试图在上使用 produce_cursors = True

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 ,而不是 produce_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映射(callback,produce_cursors = True)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆