0

I have the following play/slick 3.0 code that reads an entire table. It works well with the exception that the SQL statement doesn't add the order by (even though it applies sortBy. What could be the problem?

  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
  }
ps0604
  • 1,227
  • 23
  • 133
  • 330

1 Answers1

0

This is how to use 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
  }
ps0604
  • 1,227
  • 23
  • 133
  • 330