Appengine数据存储区未更新多个记录 [英] Appengine datastore not updating multiple records

查看:72
本文介绍了Appengine数据存储区未更新多个记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        votergroup = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE')

    for voter in votergroup:
        voter.email = 'testemail@testemail.com'
    db.put(votergroup)

上面的代码似乎没有更新appengine文档中显示的记录.我也尝试使用查询对象无济于事.我知道投票者组正在提取记录,因为调试时我对该对象进行了计数,它显示了10条记录.实际上,在db.put之前,我循环遍历了表决器.电子邮件,似乎已设置了该变量.但是,更改似乎从未使它返回到数据库.

The above code doesn't seem to be updating the records as it shows in the appengine documentation. I also tried using a query object to no avail. I know votergroup is pulling records, because I did a count on the object when debugging and it showed 10 records. In fact, before the db.put, I looped through voter.email, and it seems like the variable was set. However, the change never seems to make it back to the db.

有人知道我在做什么错吗?

Does anyone know what I might be doing wrong?

推荐答案

您需要在使用db.Query()创建的查询上调用fetch(),以使其返回实体列表.然后,您可以调用put(list_of_entities)将其全部保留.看起来像这样:

You need to call fetch() on the query you create with db.Query() to have it return a list of entities. You can then call put(list_of_entities) to persist them all. That looks like this:

voters = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE').fetch(10)

for voter in voters:
    voter.email = 'testemail@testemail.com'
db.put(voters)

如果不对查询调用fetch(),则仍然可以遍历结果,并且将使用数据存储区RPC检索所需的小批量.在查询上调用put()不会执行任何操作,但是您仍然可以对循环内的每个实体执行操作.

If you don't call fetch() on the query, you can still iterate over the results, and a datastore RPC will be made to retrieve small batches as they are needed. Calling put() on the query doesn't do anything, but you can still perform actions on each entity inside the loop.

voters_query = db.GqlQuery("SELECT * FROM Voter WHERE lastname = :1", 'AGEE')

for voter in voters_query:
    voter.email = 'testemail@testemail.com'
    voter.put()

请注意,此操作会为每个实体执行一次数据存储区调用,再为要迭代的每个批次执行一次调用.除非您不知道将返回多少项目,否则最好使用fetch().

Note that this does one datastore calls for each entity, plus one call for each batch being iterated over. It's much better to use fetch() unless you don't know how many items will be returned.

您可以使用光标来中断获取分成更大的块.我相信,尽管我找不到任何证据,但fetch()的上限为1000个实体.

You can use cursors to break fetches up into larger chunks. I believe, though I can't find any proof, that fetch() has a limit of 1000 entities.

这篇关于Appengine数据存储区未更新多个记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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