【问题标题】:Slick generic query with distinctOn带有 distinctOn 的光滑通用查询
【发布时间】: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。

【问题讨论】:

    标签: scala slick


    【解决方案1】:

    distinctOn 在 Slick 中无法正常工作,因为对特定字段/列的投影不正确。 bug 是 5 年前提出的,居然还没解决。

    【讨论】:

      猜你喜欢
      • 2019-05-17
      • 2017-01-22
      • 2020-05-14
      • 2014-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      相关资源
      最近更新 更多