如何进行“或"操作光滑地过滤 [英] How to do "OR" filter in slick

查看:62
本文介绍了如何进行“或"操作光滑地过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

光滑的我们可以使用

query.filter( m => (m.state === state1 && m.status === status1) || (m.state === state2 && m.status == status2)) 

用于where子句中的"OR"条件.但是,我的要求是我在列表中具有"OR"条件(用户将其作为URL的一部分传递).条件列表包括状态和状态元组,例如

for an "OR" condition in where clause. However my requirement is I have "OR" conditions in a list (passed by user as part of URL). Conditions list includes tuples of state and status like

List[(state1, status1),(state2, status2),(state3, status3)]

所以我想要的是能够构建||.过滤器中的语句,这样我就可以使用列表中的每个条件来生成查询,但是我不确定如何实现.或者,如果有

So what I wanted was to either be able to build the || statement inside of filter so that I can use each of the conditions from the list to generate the query but I am not sure how to achieve that. Or if there is something like

query.applyOrFilters.orFilter(condition1).orFilter(condition2) 

实际上将对查询对象执行condition1或condition2. 到目前为止,是否可以使用Slick或进行理解?

which will actually do condition1 OR condition2 on query object. Is it possible with Slick or with for comprehensions as of now ?

推荐答案

在玩它的同时,我终于找到了一种方法:-

While playing around with it, I finally found a way to do it:-

query.filter {
  m => conditions.map(n => m._13 === n._1 && m._14 === n._2).reduceLeft(_ || _)
}

其中conditions的格式为List[(String,String)]m._13映射为状态,而m._14映射为状态.

where conditions is of the form List[(String,String)], m._13 maps to state and m._14 maps to status.

希望这会帮助某人尝试同样的事情.

Hopefully this will help someone trying out same thing.

这篇关于如何进行“或"操作光滑地过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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