您可以在通用类型的doobie中制作batch update吗?
此代码:
def insertMany[T](ps: List[T]): Task[List[T]] = {
val sql = "insert into person (name, age) values (?, ?)"
Update[T](sql).updateMany(ps)
}
给我:could not find implicit value for parameter W: doobie.util.Write[T]
答案 0 :(得分:2)
是的,这里看起来是这样的:
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")))
答案基于使用@ J0kerPanda进行的gitter转换