tec*_*kuz 6 generics scala doobie
您可以在 doobie 中使用泛型类型进行批量更新吗?
这段代码:
def insertMany[T](ps: List[T]): Task[List[T]] = {
val sql = "insert into person (name, age) values (?, ?)"
Update[T](sql).updateMany(ps)
}
Run Code Online (Sandbox Code Playgroud)
给我: could not find implicit value for parameter W: doobie.util.Write[T]
是的,这里的样子:
import doobie.implicits._
import doobie._
import monix.eval.Task
import cats.data.NonEmptyList
def insertMany[T: Write](ps: NonEmptyList[T]): ConnectionIO[Int] = {
val sql = "insert into person (name, age) values (?, ?)"
Update[T](sql).updateMany(ps)
}
println(insertMany(NonEmptyList.of[String]("aa", "bb")))
Run Code Online (Sandbox Code Playgroud)
答案基于 @J0kerPanda 的 gitter 转换
| 归档时间: |
|
| 查看次数: |
966 次 |
| 最近记录: |