GQL 语法条件

发布于 2024-09-30 05:01:38 字数 644 浏览 6 评论 0原文

我有一个简单的问题:

在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别想她 2024-10-07 05:01:38

您发布的语法链接上的 GQL 语法是这样的:

SELECT [* | __key__] FROM <kind>
  [WHERE <condition> [AND <condition> ...]]
  [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
  [LIMIT [<offset>,]<count>]
  [OFFSET <offset>]

<condition> := <property> {< | <= | > | >= | = | != } <value>
<condition> := <property> IN <list>
<condition> := ANCESTOR IS <entity or key>

最后三行中的 := 表示主表达式中的 可以替换为表达式位于三个 语句中任意一个 := 右侧。

在示例中,他们选择了 * 而不是 __key__Pet,只有一个 WHERE 条件,并且没有 ORDER BYLIMITOFFSET 子句。

所以主表达式简化为:

SELECT * FROM Pet WHERE <condition>

然后我们可以替换第一个条件表达式,即:

<condition> := <property> {< | <= | > | >= | = | != } <value>

结果:

SELECT * FROM Pet WHERE <property> {< | <= | > | >= | = | != } <value>

在示例中, owner,运算符是 < code>=,且:1,即:

SELECT * FROM Pet WHERE owner = :1

根据GqlQuery 类的文档,:1 表示该值将绑定到第一个GqlQuery() 的参数(在查询之后)。因此,在示例中,该值为users.get_current_user()

更新:

我认为这两个都不起作用,因为它们都缺少双引号来结束查询字符串。但是,以下两种方法都应该有效:

query = db.GqlQuery(
    "SELECT * FROM Rep WHERE author = :1", 
    users.get_current_user())

user = users.get_current_user()
query = db.GqlQuery(
    "SELECT * FROM Rep WHERE author = :1", 
    user)

获得查询对象后,您可以对其调用 fetch() 以获取列表形式的项目。或者,您也可以直接迭代查询。

The GQL grammar on the syntax link you posted is this:

SELECT [* | __key__] FROM <kind>
  [WHERE <condition> [AND <condition> ...]]
  [ORDER BY <property> [ASC | DESC] [, <property> [ASC | DESC] ...]]
  [LIMIT [<offset>,]<count>]
  [OFFSET <offset>]

<condition> := <property> {< | <= | > | >= | = | != } <value>
<condition> := <property> IN <list>
<condition> := ANCESTOR IS <entity or key>

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> is Pet, there is only one WHERE condition, and there are no ORDER BY, LIMIT or OFFSET clauses.

So the main expression simplifies to:

SELECT * FROM Pet WHERE <condition>

We can then substitute the first condition expression, ie:

<condition> := <property> {< | <= | > | >= | = | != } <value>

Resulting in:

SELECT * FROM Pet WHERE <property> {< | <= | > | >= | = | != } <value>

In the example, <property> is owner, the operator is =, and the <value> is :1, ie:

SELECT * FROM Pet WHERE owner = :1

According to the documentation for the GqlQuery class, the :1 means that the value will be bound to the first argument to GqlQuery() (after the query). So in the example, the value is users.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:

query = db.GqlQuery(
    "SELECT * FROM Rep WHERE author = :1", 
    users.get_current_user())

user = users.get_current_user()
query = db.GqlQuery(
    "SELECT * FROM Rep WHERE author = :1", 
    user)

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文