GAE:对on进行许多查询

2024-10-03 09:19:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个productpart数据库,其中包含名为“type”的字符串属性。 我要做的是按给定的类型(有时不止一个类型)获取所有产品。在

我尝试过使用GAE过滤器方法,但无法使其正常工作。在

我唯一能做的就是做一个新的数据库GqlQuery每种类型。在

我需要按类型获取每个类型的原因是在客户端以不同的方式显示它们?在

有没有一种方法可以只使用一个查询?在

目前是这样的:

    productPartsEntries = {
                             'color' :  db.GqlQuery("SELECT * FROM ProductParts WHERE type = :type", type = 'color'),
                             'style' :  db.GqlQuery("SELECT * FROM ProductParts WHERE type = :type", type = 'style'),
                             'size' :  db.GqlQuery("SELECT * FROM ProductParts WHERE type = :type", type = 'size')
// add more....
}

…弗雷德里克


Tags: 方法字符串from数据库类型dbsizestyle
1条回答
网友
1楼 · 发布于 2024-10-03 09:19:34

您可以使用IN运算符。它将创建三个不同的查询,并在场景下将结果组合在一起。参见docs

GQL does not have an OR operator. However, it does have an IN operator, which provides a limited form of OR.

The IN operator compares value of a property to each item in a list. The IN operator is equivalent to many = queries, one for each value, that are ORed together. An entity whose value for the given property equals any of the values in the list can be returned for the query.

Note: The IN and != operators use multiple queries behind the scenes. For example, the IN operator executes a separate underlying datastore query for every item in the list. The entities returned are a result of the cross-product of all the underlying datastore queries and are de-duplicated. A maximum of 30 datastore queries are allowed for any single GQL query.

相关问题 更多 >