光滑的排序joda日期

时间:2016-07-08 12:15:17

标签: scala slick playframework-2.5

我正在使用slick-joda-mapper 2.2slick 3.1play 2.5

它没有任何问题映射Joda日期。

import com.github.tototoshi.slick.PostgresJodaSupport._

trait QuoteMapping {
      self: HasDatabaseConfigProvider[JdbcProfile] =>

      import driver.api._

      val quotes = TableQuery[Quotes]

      class Quotes(tag: Tag) extends Table[Quote](tag, "QUOTE") {
        def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)

        def startDate = column[LocalDate]("START_DATE") // All OK
        def endDate = column[LocalDate]("END_DATE") // All OK

        def pricePerDay = column[Double]("PRICE_PER_DAY")
        def totalPrice = column[Double]("TOTAL_PRICE")

        def * = (id.?, startDate, endDate, pricePerDay, totalPrice) <>(Quote.tupled, Quote.unapply)
      }

    }

是否可以在浮油中对joda日期进行排序?

/** Return a page of Quote */
def list(page: Int = 0, pageSize: Int = 10, orderBy: Int = 1, filter: String = "%"): Future[Page[(Quote)]] = {

  val offset = pageSize * page
  var query =
    quotes.filter(_.id.asColumnOf[String] like filter.toLowerCase)
      .drop(offset)
      .take(pageSize)

  orderBy match {
    case 1 => query = query.sortBy(_.id.asc)
    case 2 => query = query.sortBy(_.startDate.asc) // no .asc method
    case 3 => query = query.sortBy(_.endDate.asc) // no .asc method
    case 4 => query = query.sortBy(_.pricePerDay.asc)
    case 5 => query = query.sortBy(_.totalPrice.asc)
    case -1 => query = query.sortBy(_.id.desc)
    case -2 => query = query.sortBy(_.startDate.desc) // no .desc method
    case -3 => query = query.sortBy(_.endDate.desc) // no .desc method
    case -4 => query = query.sortBy(_.pricePerDay.desc)
    case -5 => query = query.sortBy(_.totalPrice.desc)
  }

  for {
    totalRows <- count(filter)
    list = query.result
    result <- db.run(list)
  } yield Page(result, page, offset, totalRows, pageSize)
}

2 个答案:

答案 0 :(得分:0)

由于the corresponding issue仍然开放,我认为你不能。

答案 1 :(得分:0)

我只是输入了错误:

org.joda.time.LocalDate

它是:

java.time.LocalDate

一切按预期工作,我希望它可以帮助某人