你会如何在SLICK写这个查询?
DB.withSession {
implicit session =>
Tokens.where(_.expirationTime < DateTime.now ).delete
}
DateTime.now的类型为org.joda.time.DateTime
和_.expirationTime是相同类型的类型映射列 .
我收到这个错误
[error] UserService.scala:80: value < is not a member of scala.slick.lifted.Column[org.joda.time.DateTime]
[error] Tokens.where(_.expirationTime < DateTime.now ).delete
[error] ^
[error] one error found
现在使用此表单中的查询 .
3 回答
我的猜测是JodaTime类型不是开箱即用的支持类型 . 如果您将该列更改为
java.sql.Timestamp
并使用Timestamp
作为比较值,那么事情就可以了 . 如果要在光滑的列映射中使用joda类型,可能需要查看以下内容:https://github.com/tototoshi/slick-joda-mapper
导入
com.github.tototoshi.slick.JodaSupport._
为我解决了问题 .我会怎么做:
让我们假设您的Token类看起来像这样,并且您使用mysql:
例如 . 依赖关系:
那么你需要做的就是:
如果您使用除mysql之外的任何其他数据库,则需要更改导入和依赖项 .