我試圖動態地包括一個sortBy到我的查詢,它根據查詢參數的字符串名稱進行排序。在Slick 3中,這已被證明非常棘手。目前,我的設置是:動態sortwith與油滑3
trait Model {
type ATable <: AbstractTable[_]
def tableQuery: TableQuery[ATable]
def sortMap: Map[String, Rep[_]]
private def sortKey[T](e: ATable, sort: (String, SortOrder)): ColumnOrdered[_] = sort match {
case (field, SortOrder.Asc) => ColumnOrdered(sortMap.getOrElse(field, throw new ClientException(s"Can't sort by $field")), Ordering(Ordering.Asc))
case (field, SortOrder.Desc) => ColumnOrdered(sortMap.getOrElse(field, throw new ClientException(s"Can't sort by $field")), Ordering(Ordering.Desc))
}
def all(sort: (String, SortOrder)) = tableQuery.sortBy(sortKey(_, sort)).result
}
object User extends Model {
type ATable = Tables.User
val tableQuery = Tables.User
val sortMap = Map("id" -> tableQuery.id)
}
但運行db.run(User.all(("id", SortOrder.Asc))
引發以下錯誤:
slick.SlickException: No type for symbol name found in Vector[t2<@t3<UnassignedType>>]
有誰知道一個更好的解決方案,或者我要去哪裏錯了嗎?