我刚开始使用 scala 并想建立与我的数据库的连接。
(我的知识来自https://www.scala-exercises.org/上的 scala/doobie 教程)
现在这里是代码:
import doobie._
import doobie.implicits._
import cats.effect._
import cats.implicits._
import doobie.hikari._
...
val transactor: Resource[IO, HikariTransactor[IO]] =
for {
ce <- ExecutionContexts.fixedThreadPool[IO](32) // our connect EC
be <- Blocker[IO] // our blocking EC
xa <- HikariTransactor.newHikariTransactor[IO](
"org.h2.Driver", // driver classname
"jdbc:mysql://localhost:3306/libraries", // connect URL
"root", // username
"", // password
ce, // await connection here
be // execute JDBC operations here
)
} yield xa
当我尝试构建我的代码时,我收到以下错误消息:
错误:(25, 53) 找不到 ContextShift[cats.effect.IO] 的隐式值:
从效果库中导入 ContextShift[cats.effect.IO]
如果使用 IO,请使用cats.effect.IOApp 或使用cats.effect.IO.contextShift xa <- HikariTransactor.newHikariTransactor[IO](
现在我有两个问题:
- 究竟是什么问题?
- 我如何解决它?