Appengine 数据存储区未更新多条记录

发布于 2024-09-15 21:06:10 字数 530 浏览 4 评论 0原文

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

    for voter in votergroup:
        voter.email = '[email protected]'
    db.put(votergroup)

上面的代码似乎没有像 appengine 文档中显示的那样更新记录。我也尝试使用查询对象但无济于事。我知道 votergroup 正在提取记录,因为我在调试时对对象进行了计数,它显示了 10 条记录。事实上,在 db.put 之前,我循环访问了 voter.email,看起来变量已经设置了。然而,更改似乎永远不会返回到数据库。

有谁知道我可能做错了什么?

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

    for voter in votergroup:
        voter.email = '[email protected]'
    db.put(votergroup)

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

森末i 2024-09-22 21:06:10

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

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

for voter in voters:
    voter.email = '[email protected]'
db.put(voters)

如果您不对查询调用 fetch(),您仍然可以迭代结果,并且将根据需要进行数据存储 RPC 来检索小批量数据。对查询调用 put() 不会执行任何操作,但您仍然可以对循环内的每个实体执行操作。

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

for voter in voters_query:
    voter.email = '[email protected]'
    voter.put()

请注意,这会对每个实体执行一次数据存储调用,并为迭代的每个批次执行一次调用。除非您不知道将返回多少项,否则最好使用 fetch()

您可以使用游标将提取内容分解为更大的内容大块。尽管我找不到任何证据,但我相信 fetch() 的实体数量限制为 1000 个。

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 = '[email protected]'
db.put(voters)

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 = '[email protected]'
    voter.put()

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.

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.

只有一腔孤勇 2024-09-22 21:06:10

试试这个:

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

for voter in votergroup:
    voter.email = '[email protected]'
    voter.put()

我认为没有办法使用应用程序引擎进行批量编辑。

Try this instead:

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

for voter in votergroup:
    voter.email = '[email protected]'
    voter.put()

I don't think there is a way to do mass edits with the app engine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文