【发布时间】:2011-04-05 22:45:39
【问题描述】:
在使用 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)
我对数据存储区以及最后一行的等价物特别感兴趣。
datastore plus documentation 的示例代码根本不处理参数(在事务中硬编码)。
【问题讨论】:
标签: python google-app-engine transactions google-cloud-datastore