带有OR条件的Google数据存储过滤器 [英] Google Datastore filter with OR condition

查看:151
本文介绍了带有OR条件的Google数据存储过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在使用复合查询过滤器,只需要一个基本的OR条件。

我正在使用Google App Engine上的NodeJS和Datastore数据库。 p>

示例:具有Done = false或优先级= 4的查询任务

  const query = datastore.createQuery('Task')
.filter('done','=',false)//如何使它成为OR条件?
.filter('priority','=',4);

但是,根据文档

lockquote

云数据存储目前仅支持将过滤器
与AND运算符组合在一起。


什么是实现基本OR条件而不运行两个完全独立的查询,然后结合结果?



更新

我的解决方案在我的其他文章中详细介绍。任何反馈意见,以改善解决方案将不胜感激,因为我仍然在学习NodeJS。

解决方案

目前无法实现查询与一个条件 - 这是你引用的说明的意思。

一些客户端库为类操作提供了一些(有限)支持。从限制查询


索引查询机制的性质对查询的功能施加了某些限制
。云数据存储查询不支持
子字符串匹配,不区分大小写的匹配或者所谓的全文
搜索。 NOT OR != 运算符不是本地支持
,但某些客户端库可能会在Cloud
Datastore之上添加支持。


但是AFAIK no这样的库可用于NodeJS。如果你只需要一些特定的查询,一种可能的方法是计算(在编写实体的时候)一个额外的属性和所需的结果例如,假设你想要一个带有




  • .filter('status','=','排队')

  • .filter('status','=','running')



每次您都可以计算一个属性,如 not_done 状态更改并将其设置为 true 如果 status 排队运行 false 否则。然后你可以使用具有相同语义的 .filter('not_done','=',true)>。当然,这并不方便,但它可能会让你超越障碍。


I am working with NodeJS on Google App Engine with the Datastore database.

I am using composite query filter and just need a basic "OR" condition.

Example: Query Tasks that have Done = false OR priority = 4

const query = datastore.createQuery('Task')
  .filter('done', '=', false) //How to make this an OR condition?
  .filter('priority', '=', 4);

However, according to the documentation:

Cloud Datastore currently only natively supports combining filters with the AND operator.

What is a good way to achieve a basic OR condition without running two entirely separate queries and then combining the results?

UPDATE

I have my solution described in detail here in my other post. Any feedback for improvements to the solution would be appreciated since I'm still learning NodeJS.

解决方案

Not currently possible to achieve a query with an OR condition - this is what the note you quoted means.

Some client libraries provide some (limited) support for OR-like operations. From Restrictions on queries:

The nature of the index query mechanism imposes certain restrictions on what a query can do. Cloud Datastore queries do not support substring matches, case-insensitive matches, or so-called full-text search. The NOT, OR, and != operators are not natively supported, but some client libraries may add support on top of Cloud Datastore.

But AFAIK no such library is available for NodeJS.

If you only have a need for a few specific such queries one possible approach would be to compute (at the time of writing the entities) an additional property with the desired result for such query and use equality queries on that property instead.

For example, assuming you'd like a query with OR-ing the equivalents of these filters:

  • .filter('status', '=', 'queued')
  • .filter('status', '=', 'running')

You could compute a property like not_done every time status changes and set it to true if status is either queued or running and false otherwise. Then you can use .filter('not_done', '=', true) which would have the same semantics. Granted, it's not convenient, but it may get you past the hurdle.

这篇关于带有OR条件的Google数据存储过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆