Play Slick:select * from table忽略sortBy

时间:2016-01-29 13:29:27

标签: playframework playframework-2.0 slick play-slick

我有以下play / slick 3.0代码读取整个表格。它适用于SQL语句不添加order by的例外(即使它适用sortBy。可能是什么问题?

  def readMany =  {
    val db = Database.forConfig("dbconfig")
    var list = new ListBuffer[UserVO]()
    try {
      val users = TableQuery[UserDB]
      val action = users.result
      users.sortBy(_.userid)
      val future = db.run(action).map(_.foreach {
        case (u) => list += u
      })
      val result = Await.result(future, 10 seconds)
      println(action.statements.head)  // <-- prints "select userid,col1,col2 from users"
    } finally db.close
    list
  }

1 个答案:

答案 0 :(得分:0)

这是使用sortBy的方法:

 def readMany =  {
    val db = Database.forConfig("dbconfig")
    var list = new ListBuffer[UserVO]()
    try {
      val users = TableQuery[UserDB]


      val action = users.sortBy(_.userid).result  <-- sortBy example

      val future = db.run(action).map(_.foreach {
        case (u) => list += u
      })
      val result = Await.result(future, 10 seconds)
      println(action.statements.head)  
    } finally db.close
    list
  }