实现它的一种方法是这样的:
val Now = DateTime.Now val today = Now.toLocalDate val tomorrow = today.plusDays(1) val startOfToday = today.toDateTimeAtStartOfDay(Now.getZone) val startOfTomorrow = tomorrow.toDateTimeAtStartOfDay(Now.getZone) val todayLogItems = logItems.filter(logItem => logItem.MyDateTime >= startOfToday && logItem.MyDateTime < startOfTomorrow ).list
有没有办法以更简洁的方式编写查询?有点像:
logItems.filter(_.MyDateTime.toDate == DateTime.Now.toDate).list
我问这个是因为LINQ to NHibernate是可以实现的(Fetching records by date with only day part comparison using nhibernate).
解决方法
除非Slick joda映射器增加对比较的支持,否则你运气不好,除非你自己添加它.为了给它一个镜头,这些可能是有用的指针:
* http://slick.typesafe.com/doc/2.0.0/userdefined.html
* http://slick.typesafe.com/doc/2.0.0/api/#scala.slick.lifted.ExtensionMethods
* https://github.com/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala
* http://slick.typesafe.com/doc/2.0.0/userdefined.html
* http://slick.typesafe.com/doc/2.0.0/api/#scala.slick.lifted.ExtensionMethods
* https://github.com/slick/slick/blob/2.0.0/src/main/scala/scala/slick/lifted/ExtensionMethods.scala
我创建了一张在Slick中查看它的票证:https://github.com/slick/slick/issues/627
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。