【发布时间】:2012-09-09 12:38:42
【问题描述】:
我对 NDB 投影查询的工作方式以及缓存在后台的行为方式有一些疑问
所以给定一个类似的模型:
class Users(ndb.Model):
user_name = ndb.StringProperty(required=True)
user_email = ndb.StringProperty(required=True)
user_password = ndb.StringProperty(required=True)
@classmethod # THIS ONE DOES NOT WORK
def get_profile_info(cls, id):
return ndb.Key(Users, id).get(projection=[Users.user_name])
@classmethod # THIS ONE WORKS
def get_profile_info(cls, id):
return Users.query(Users.key == ndb.Key(Users, id)).get(projection=[Users.user_name])
为什么第一个类方法会引发“TypeError: Unknown configuration option ('projection')”?我不能简单地调用直接获取键的投影,而不必查询键吗?
其次,关于缓存,我不确定我是否正确理解了这个帖子:NDB Caching When Using Projected Queries
预测的查询不会被缓存吗?这是否意味着直接调用 get()(并获取整个实例)以便缓存而不是投影更好?
提前致谢!
【问题讨论】:
标签: google-app-engine python-2.7 google-cloud-datastore