Google 应用引擎中的查询问题
我对 sql 非常陌生,对 Google 应用程序引擎中使用的 GQL 还很陌生。我已设法将我的数据推送到 Google 服务器,但我无法找到从已加载到数据存储的实体中进行查询的方法。
问题是,我只想查询由用户 id 标记的用户联系人的姓名和号码,除了下面给出的其他列之外,
Name Number User_id Country
Rob 0065114146 654351 singapore
Mark 0065132411 654351 singapore
Tina 0065221916 846611 singapore
Nick 0065214126 846611 singapore
这是我的 Models.py 文件,其中有我的 MyContacts 实体定义,
Class MyContacts(db.Model):
Name = db.StringProperty(required=True)
Number = db.PhoneNumberProperty(required=True)
User_id = db.IntegerProperty(required=True)
Country = db.StringProperty()
我正在获取用户id 作为 UI 的输入,但我无法找到使用查询调出数据的方法。如果有人可以帮助我在 GQL 中创建查询,这对我来说将是一个很大的帮助。 我尝试过各种类似 SELECT * FROM MyContacts WHERE __key__ = KEY('user_id',654351) 但我什么也没得到。
请帮帮我。
I am very new to sql and more over GQL used in Google app engine. I have managed to push my data to the Google servers but I am not able to figure out a way to query from the entities I've loaded to the datastrore.
Here's the problem, i want to query only the names and numbers of a user's contacts marked by user id apart from other columns like given below,
Name Number User_id Country
Rob 0065114146 654351 singapore
Mark 0065132411 654351 singapore
Tina 0065221916 846611 singapore
Nick 0065214126 846611 singapore
This is my Models.py file in which I have my MyContacts Entity definition,
Class MyContacts(db.Model):
Name = db.StringProperty(required=True)
Number = db.PhoneNumberProperty(required=True)
User_id = db.IntegerProperty(required=True)
Country = db.StringProperty()
I am taking the user id as input from the UI but I am not able to figure out a way to bring up the data using the query. Please if any one can help me coin the query in GQL it would be a great help for me.
I've tried all sorts like SELECT * FROM MyContacts WHERE __key__ = KEY('user_id',654351)
but i get nothing.
Please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 User_id 是一个 IntegerProperty,您需要像这样查询:
或等效地使用查询:
请注意,如果“User_id”取自 Users API User 对象,则不应将其转换为 int - 它不能保证适合64 位,因此您应该将其存储为字符串或 UserProperty。
Since User_id is an IntegerProperty, you need to query like this:
or equivalently with a query:
Note that if 'User_id' is taken from a Users API User object, you should not be casting it to an int - it's not guaranteed to fit in 64 bits, so you should either be storing it as a string or as a UserProperty.