3

http://code.google.com/appengine/docs/python/datastore/entities.html#Saving_Getting_and_Deleting_Entities

获取实体的批处理操作如下:

一批得到。实体 = db.get([k1, k2, k3])

如何在不提供密钥的情况下获取所有实体?

4

2 回答 2

3

我对此有一个解决方案,可以在 Datastore Queries - Query interface example中找到:

Query q = new Query("Person") 
        PreparedQuery pq = datastore.prepare(q);  
    for (Entity result : pq.asIterable()) {   
       String firstName = (String) result.getProperty("firstName");   
       String lastName = (String) result.getProperty("lastName");   
       Long height = (Long) result.getProperty("height");   
       System.out.println(lastName + " " + firstName + ", " + height.toString() + "inches tall"); 
}

我没有在查询中添加过滤器,因为它从数据存储区返回所有实体。

于 2011-02-09T05:45:53.263 回答
0

一个简单的方法是使用gql,条件始终为真并获取结果。例如,如果您的实体有一个名称为 StringKey 的字符串字段,您可以这样做:

entities = db.gql("WHERE StringKey >''").fetch(1000)

请注意,获得超过 1000 个实体是可能的,但在 GAE 中并不简单,请参阅此讨论

于 2011-02-07T15:19:22.857 回答