如何使用实体键在 GQL 中查询

发布于 2024-08-16 08:02:57 字数 329 浏览 2 评论 0原文

如何在 Google App Engine 数据查看器中使用 GQL 编写针对实体键的查询?

在查看器中,第一列 (Id/Name) 显示为 name=_1,在详细信息视图中,它显示的键为

Decoded entity key: Programme: name=_1
Entity key: agtzcG9................... 

This query does not work:

SELECT * FROM Programme where name = '_1'

How do I write a query against the entity key using GQL in the Google App Engine Data Viewer ?

In the viewer, the first column (Id/Name) displays as name=_1, in the detail view it shows the key as

Decoded entity key: Programme: name=_1
Entity key: agtzcG9................... 

This query does not work:

SELECT * FROM Programme where name = '_1'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

暗地喜欢 2024-08-23 08:02:57

您可以使用实体的密钥来检索它:

SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')

并且,您应该能够使用类似的名称进行查询:

SELECT * FROM Programme where __key__ = KEY(Programme, '_1')

请注意,这不是您希望在 AppEngine 应用程序中执行的操作;正如尼克在评论中指出的那样,这是对时间的巨大浪费。实际上,这个例子只是为了向您展示如何在管理控制台中通过 Key 进行查询。

You can use the entity's key to retrieve it:

SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')

And, you should be able to query using the name similarly:

SELECT * FROM Programme where __key__ = KEY(Programme, '_1')

Note that this is not something that you would want to do in your AppEngine application; as Nick notes in his comment, it is a huge waste of time. Really, this example is only good to show you how to query by Key in the Admin console.

假装爱人 2024-08-23 08:02:57

对于数字 ID,可以使用类似于按名称查询的表单:

SELECT * from Programme where __key__ = KEY('Programme', 1234567)

我发现此表单在管理控制台中特别有用。

For numeric IDs, a form similar to the query-by-name works:

SELECT * from Programme where __key__ = KEY('Programme', 1234567)

I found this form especially useful in the Admin Console.

┾廆蒐ゝ 2024-08-23 08:02:57

您根本不需要查询来通过键获取实体 - 您可以简单地通过键获取实体。在 Python 中,您可以使用 MyModel.get_by_key_name('_1') 来执行此操作。这比 Adam 建议的使用查询快 3 到 5 倍。

You don't need to query to get an entity by key at all - you can simply fetch the entity by its key. In Python, you can do this with MyModel.get_by_key_name('_1'). This is 3 to 5 times faster than Adam's suggestion of using a query.

时光瘦了 2024-08-23 08:02:57

按键查询时,需要精确匹配键,包括父项,而不仅仅是 ID 或名称。当然,如果parent为null,如上例所示,实体的ID或Name和类型就足够了。

如果您有已经编码的实体密钥,则可以使用它,例如:

SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')

对于上面的简单示例,

SELECT * FROM Programme where __key__ = KEY('Programme', '_1')

就可以了,但是如果您的密钥有一个父项,例如

Paren: id=123

那么查询将是

SELECT * FROM Programme where __key__ = KEY('Paren', 123, 'Programme', '_1')

如果父项本身有一个父项,则需要也添加一下。如需了解更多详情,请参阅官方 GQL 文档

似乎没有一种方法可以选择具有相同 ID 或名称的所有内容,而不管其父级如何。

When querying by key, you need to match the key exactly, including the parent and not just the ID or name. Of course, if the parent is null, as in the example above, the ID or Name and the type of entity is enough.

If you have the already encoded entity key, you can just use that like:

SELECT * FROM Programme where __key__ = KEY('agtzcG9...................')

For the simple example above,

SELECT * FROM Programme where __key__ = KEY('Programme', '_1')

will do, but if your key has a parent, like

Paren: id=123

Then the query would be

SELECT * FROM Programme where __key__ = KEY('Paren', 123, 'Programme', '_1')

If the parent itself has a parent, you need to add that too. For more details see the official GQL documentation.

There does not appear to be a way to select everything with the same ID or name regardless of parent.

傲世九天 2024-08-23 08:02:57

对此简单说明一下:当我在 KEY 中的任何参数周围使用任何引号时,调用会失败(在管理控制台中,我收到错误弹出窗口)。

例如,对于 ID/名称为 12345 的“mytype”类型,这不起作用

SELECT * FROM mytype WHERE __key__ = KEY('mytype', '12345')

但这确实有效:

SELECT * FROM mytype WHERE __key__ = KEY(mytype, 12345)

Just a quick note on this: When I use any quotes around any of the args in KEY, the call fails (in the admin console I get the error popup).

For example, for type "mytype" with ID/Name 12345, this does NOT work:

SELECT * FROM mytype WHERE __key__ = KEY('mytype', '12345')

But this does:

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