GQL 语法条件
我有一个简单的问题:
在 GQL 语法摘要 中,
<condition> := <property> {< | <= | > | >= | = | != } <value>
但在示例
if users.get_current_user():
user_pets = db.GqlQuery("SELECT * FROM Pet WHERE owner = :1",
users.get_current_user())
:1
是什么?
根据语法,应该有 :=
。
谢谢。
I have a simple question:
In GQL syntax summary
<condition> := <property> {< | <= | > | >= | = | != } <value>
but in an example here
if users.get_current_user():
user_pets = db.GqlQuery("SELECT * FROM Pet WHERE owner = :1",
users.get_current_user())
What is :1
?
According to syntax there should be :=
there.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您发布的语法链接上的 GQL 语法是这样的:
最后三行中的
:=
表示主表达式中的
可以替换为表达式位于三个
语句中任意一个:=
右侧。在示例中,他们选择了
*
而不是__key__
,
是Pet
,只有一个WHERE
条件,并且没有ORDER BY
、LIMIT
或OFFSET
子句。所以主表达式简化为:
然后我们可以替换第一个条件表达式,即:
结果:
在示例中,
是owner
,运算符是 < code>=,且
为:1
,即:根据
GqlQuery
类的文档,:1 表示该值将绑定到第一个GqlQuery()
的参数(在查询之后)。因此,在示例中,该值为users.get_current_user()
。更新:
我认为这两个都不起作用,因为它们都缺少双引号来结束查询字符串。但是,以下两种方法都应该有效:
获得查询对象后,您可以对其调用
fetch()
以获取列表形式的项目。或者,您也可以直接迭代查询。The GQL grammar on the syntax link you posted is this:
The
:=
in the last three lines means that<condition>
in the main expression can be replaced with the expression to the right of the:=
in any of the three<condition>
statements.In the example, they have chosen to select
*
instead of__key__
, the<kind>
isPet
, there is only oneWHERE
condition, and there are noORDER BY
,LIMIT
orOFFSET
clauses.So the main expression simplifies to:
We can then substitute the first condition expression, ie:
Resulting in:
In the example,
<property>
isowner
, the operator is=
, and the<value>
is:1
, ie:According to the documentation for the
GqlQuery
class, the :1 means that the value will be bound to the first argument toGqlQuery()
(after the query). So in the example, the value isusers.get_current_user()
.Update:
I don't think either of those would work, because they are both missing a double quote to end the string of the query. However, both of the following should work:
Once you have the query object you can call
fetch()
on it to get the items as a list. Or, you can also iterate directly over the query.