Slick PostgreSQL: could not find implicit value for parameter tt: slick.ast.TypedType[List[xxx.UseCase]]

19 Jan
2021

When you’re using PostgreSQL together with Slick, chances are high, that you’re also using the Slick-PG library. You probably came to this post, because you try to map your custom ADT to a List/Sequence of that and want to store it as a text[] (or other array) in PostgreSQL. When trying to do so, the compiler gave you an error like:

could not find implicit value for parameter tt: slick.ast.TypedType[List[xxx.UseCase]]

You already tried creating a MappedColumnType[UseCase, String], but for some reason, Slick hasn’t picked it up / is not using it for Sequences / Lists.

Go no further, the solution is near!

trait MyPostgresProfile
extends ExPostgresProfile
with PgArraySupport
with PgDate2Support
with PgRangeSupport
with PgHStoreSupport {
def pgjson = "jsonb"
// Add back `capabilities.insertOrUpdate` to enable native `upsert` support; for postgres 9.5+
override protected def computeCapabilities: Set[Capability] =
super.computeCapabilities + slick.jdbc.JdbcCapabilities.insertOrUpdate
override val api = MyAPI
object MyAPI extends API with ArrayImplicits with DateTimeImplicits with RangeImplicits with HStoreImplicits {
val strSimpleJdbcArrayListType: SimpleArrayJdbcType[String] = new SimpleArrayJdbcType[String]("text")
implicit val strListTypeMapper: JdbcType[List[String]] =
strSimpleJdbcArrayListType.to(_.toList)
// here we
implicit val useCaseListTypeMapper: JdbcType[List[UseCase]] = strSimpleJdbcArrayListType
.mapTo[UseCase](str => UseCase.of(str), uc => uc.label)
.to(_.toList)
}

Simply create a new JdbcType[List[YourType]] based on the SimpleArrayJdbcType[String] and then use the mapTo[YourType] method.

I hope you found this helpful!

Comment Form

top