正确使用浮油过滤器 [英] right usage of slick filter
本文介绍了正确使用浮油过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Slick来访问数据库.我想这样查询:
I'm using slick to access database. I want to query like this:
case class Coupon(couponId: Long, shopId: String)
class Coupons(tag: Tag) extends Table[Coupon](tag, "coupons"){
def couponId = column[Long]("coupon_id")
def shopId = column[String]("shop_id")
override def * = (couponId, shopId) <> (Coupon.tupled, Coupon.unapply)
}
object Coupons extends TableQuery(new Coupons(_)){
def findCouponBy(couponId: Long, shopId: Option[String]) = {
val s = DB.createSession()
try {
val q = for {
coupon <- this.filter(c => c.couponId === couponId &&
shopId.map(s => c.shopId === s).getOrElse(true)
} yield coupon
s.database.run(q.result)
} finally s.close
}
}
我认为这可能有效.但是,编译器告诉我 错误:(126,-1)播放2编译器: 类型不匹配; 找到:任何 必需:slick.lifted.Rep [?]
I thought this might work. However, the compiler tells me that Error:(126, -1) Play 2 Compiler: type mismatch; found : Any required: slick.lifted.Rep[?]
问题就在这里: shopId.map(s => c.shopId === s).getOrElse(true)
Problem lies on here: shopId.map(s => c.shopId === s).getOrElse(true)
我想知道如何进行这项工作.
I'm wondering how I can make this work.
我正在使用光滑的3.0.0-RC
I'm using slick 3.0.0-RC
推荐答案
使用slick.lifted.LiteralColumn(true)
Scala的类型推断限制
Scala's type infer limitation
这篇关于正确使用浮油过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文