在NDB和GAE中put()后评估一个条件 [英] Evaluate a condition after put() in NDB and GAE

查看:108
本文介绍了在NDB和GAE中put()后评估一个条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将实体放入数据存储区并使用NDB后,我需要执行一些代码。

I need to execute some code after i've put my entity in the datastore, with NDB.

比方说,我有类似的东西。

let's say i have something like this.

ent=Entity()
ent.put()

def after_put():
    assert ...

如何在不手动调用函数的情况下实现该功能?是否有某种触发器或回调函数可用?

How can i achieve that without calling manually the function? Is there some sort of trigger or callback i could use?

推荐答案

是的,您可以使用钩子。

Yes, you can use "hooks".


NDB提供轻量级挂钩机制。通过定义一个钩子,应用程序可以在某种类型的操作之前或之后运行一些代码;例如,Model可能会在每个get()之前运行某个函数。使用相应方法的同步,异步和多版本时,会运行挂钩函数。例如,pre-get钩子将应用于所有get(),get_async()和get_multi()。

NDB offers a lightweight hooking mechanism. By defining a hook, an application can run some code before or after some type of operations; for example, a Model might run some function before every get(). A hook function runs when using the synchronous, asynchronous and multi versions of the appropriate method. For example, a "pre-get" hook would apply to all of get(), get_async(), and get_multi().

https://developers.google.com/appengine/docs/python/ndb/entities#hooks

这篇关于在NDB和GAE中put()后评估一个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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