开发者

How to get all entity kinds from GAE server?

How ca开发者_运维百科n I get all entity kinds from GAE server? Is this possible? I want to make a DB manager tool for GAE.


You can use the Metadata API. For example:

Query query = new Query(Entities.KIND_METADATA_KIND);
DatastoreService datastoreService = DatastoreServiceFactory.getDatastoreService();

Iterable<Entity> entityIterable = datastoreService.prepare(query).asIterable();

for(Entity entity : entityIterable) {
    System.out.println("Entity kind: " + entity.getKey().getName());
}


The best way to do this is to programmatically read the datastore stats. See the docs for doing so in Python or Java. Here's a simple example in Python:

>>> from google.appengine.ext.db import stats
>>> kinds = stats.KindStat.all().fetch(1000)
>>> kind_names = [x.kind_name for x in kinds]
>>> kind_names
[u'A', u'AAFoo', u'AModel', u'ASDBD', u'Abc', u'Accumulator', u'Activity', # ...

You can test this for yourself in the interactive console.

The datastore stats also provide piles of other details that will be useful in writing a datastore management tool. Good luck!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜