Scala doobie snippet with generic parameter

I am trying to abstract the insertion of objects of different types into sql tables of a similar structure. Here is what I am trying to do:

class TableAccess[A : Meta](table: String) { def insert(key: String, a: A): ConnectionIO[Unit] = { (fr"insert into " ++ Fragment.const(table) ++ fr" values ($key, $a);").update.run.map(_ => ()) } } 

But I get this compilation error:

 [error] diverging implicit expansion for type doobie.util.param.Param[A] [error] starting with method fromMeta in object Param [error] (fr"insert into " ++ Fragment.const(table) ++ fr" values ($key, $a);").update.run.map(_ => ()) 

All I can find in the documentation:

doobie allows you to interpolate values โ€‹โ€‹of any type (and parameters) with an instance of Meta, which includes ...

But this does not seem to be enough; What correct types / imports / conversions do I need?

+5
source share
1 answer

When the compiler allows an implicit search for its one of a certain type in the current scope. Here it seems that he found more than one in his search for a tree.

This is not a question of a missing type or import, it is more like you have too many of them, and the compiler figure is correct. Try removing some implicit ones and see how it works or pass them explicitly.

0
source

Source: https://habr.com/ru/post/1275412/


All Articles