【发布时间】:2020-07-30 23:47:25
【问题描述】:
我想在 table 上使用 distinctOn 进行通用的光滑查询,以计算列中的不同元素。
def countDistinct(table: TableQuery[_], column: Rep[_]): DBIO[Int] =
table.distinctOn(_ => column).length.result
上面的代码无法编译,因为:
No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection,
[error] you use an unsupported type in a Query (e.g. scala List),
[error] or you forgot to import a driver api into scope.
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: slick.lifted.Rep[_]
[error] Unpacked type: T
[error] Packed type: Any
[error] table.distinctOn(_ => column).length.result
FlatShapeLevel 而不是 Rep[_] 也不起作用。我正在使用 slick 3。
【问题讨论】: