我有以下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
}
答案 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
}