How to get the number of rows in a table in a Datastore?

后端 未结 3 1475
故里飘歌
故里飘歌 2020-12-31 21:31

In many cases, it could be useful to know the number of rows in a table (a kind) in a datastore using Google Application Engine.
There is not clear and fast solution . A

3条回答
  •  [愿得一人]
    2020-12-31 21:46

    There's no concept of "Select count(*)" in App Engine. You'll need to do one of the following:

    1. Do a "keys-only" (index traversal) of the Entities you want at query time and count them one by one. This has the cost of slow reads.
    2. Update counts at write time - this has the benefit of extremely fast reads at a greater cost per write/update. Cost: you have to know what you want to count ahead of time. You'll pay a higher cost at write time.
    3. Update all counts asynchronously using Task Queues, cron jobs or the new Mapper API. This has the tradeoff of being semi-fresh.

提交回复
热议问题