Slick 3.1.x中的更新语句不正确

时间:2016-12-12 00:56:56

标签: scala slick slick-3.0

我有以下Slick行动,更新2016年的所有日期,不包括星期六和星期日

  val action = dates.filter( d => d.year === 2016 && 
            d.weekDay != "Sat" && d.weekDay != "Sun").map(x => (x.isHoliday)).update(0)
  Await.result(db.run(action), Duration.Inf).value
  val sql = action.statements.head
  println(sql)

问题是更新没有按预期工作,sql打印

update `dates` set `is_holiday` = ? where ((`dates`.`year` = 2016) and true) and true

何时打印

update `dates` set `is_holiday` = ? where `dates`.`year` = 2016 
        and `dates`.`week_day` != 'Sat' and `dates`.`week_day` != 'Sun'

这句话有什么问题?

1 个答案:

答案 0 :(得分:2)

我相信您不小心使用了scala !=运算符而不是Slick =!=函数。试试这个:

val action = dates.filter(d => d.year === 2016 && d.weekDay =!= "Sat" && d.weekDay =!= "Sun").map(x => (x.isHoliday)).update(0)

你也可以试试这个:

val weekendDays = Set("Sat", "Sun")
val action = dates.filter(d => d.year === 2016 && !d.weekDay.inSet(weekendDays))