Reputation: 15385
I have this function that inserts a One To Many relationship representation between 3 tables:
def insertRelations(cs: TableA): Fragment = {
sql"""INSERT INTO my_schema.table_a (
id,
name,
dataType,
longName,
externalNumber,
) VALUES (
${cs.name},
${cs.dataType},
${cs.longName},
${cs.externalNumber},
)"""
.update.withUniqueGeneratedKeys[Int]("id")
.flatMap { tableAId =>
val bSeqs: Seq[TableB] = cs.tableBSeqs
bSeqs.traverse_ { elem =>
sql"""insert into table_b (
tableAId,
externalName,
readValue,
isFormatted,
meanValue,
createdAt,
updatedAt
) VALUES (
${elem.tableAId},
${elem.externalName},
${elem.readValue},
${elem.isFormatted},
${elem.meanValue},
)"""
.update.withUniqueGeneratedKeys[Long]("id")
.flatMap { tableCId =>
val cSeqs: Seq[TableC] = cs.tableCSeqs
cSeqs.traverse_ { elem =>
sql"""insert into table_c (...., ...., ....) values ($...., $...., ....)"""
.update.run
}
}
}
}
}
I have the following imports in scope:
import doobie.Fragment
import doobie.implicits._
import cats.implicits._
When I tried to compile this, it ran into the following error:
ambiguous implicit values:
[error] both lazy value WeakAsyncBlobIO in trait Instances of type doobie.WeakAsync[doobie.free.BlobIO]
[error] and lazy value WeakAsyncCallableStatementIO in trait Instances of type doobie.WeakAsync[doobie.free.CallableStatementIO]
[error] match expected type cats.Applicative[G]
[error] bseqs.traverse_ { elem =>
Both my traverse throws up this ambiguous implicit error. Is there any implicit scope that I'm missing?
Upvotes: 0
Views: 127