Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为Datastore Plus(NDB)中的事务提供参数_Python_Google App Engine_Transactions_Google Cloud Datastore - Fatal编程技术网

Python 为Datastore Plus(NDB)中的事务提供参数

Python 为Datastore Plus(NDB)中的事务提供参数,python,google-app-engine,transactions,google-cloud-datastore,Python,Google App Engine,Transactions,Google Cloud Datastore,在使用Datastore Plus时,我很难确定如何将参数传递到事务中 有人可以重写这个常规数据存储示例代码吗 from google.appengine.ext import db class Accumulator(db.Model): counter = db.IntegerProperty() def increment_counter(key, amount): obj = db.get(key) obj.counter += amount obj.

在使用Datastore Plus时,我很难确定如何将参数传递到事务中

有人可以重写这个常规数据存储示例代码吗

from google.appengine.ext import db

class Accumulator(db.Model):
    counter = db.IntegerProperty()

def increment_counter(key, amount):
    obj = db.get(key)
    obj.counter += amount
    obj.put()

q = db.GqlQuery("SELECT * FROM Accumulator")
acc = q.get()

db.run_in_transaction(increment_counter, acc.key(), 5)
我特别感兴趣的是数据存储加上最后一行的等价物


的示例代码根本不处理参数(在事务中硬编码)。

假设您可以从文档中学习示例,答案是使用lambda(或命名的helper函数)。例如


假设您可以遵循文档中的示例,答案是使用lambda(或命名的helper函数)。例如

yield context.transaction(lambda: increment_counter(acc.key(), 5))