我刚刚开始使用 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
Run Code Online (Sandbox Code Playgroud)
当我尝试构建我的代码时,我收到以下错误消息:
错误:(25, 53) 无法找到 ContextShift[cats.effect.IO] 的隐式值:
从效果库导入 ContextShift[cats.effect.IO]
如果使用 …
我正在尝试通过具有固定公开端口的测试容器运行 Couchbase v.5.1.1 docker 容器以进行测试,例如:
trait CouchbaseTestEnvironment extends ForAllTestContainer {
this: Suite =>
def couchbaseContainer: FixedHostPortGenericContainer = {
val consumer = new Slf4jLogConsumer(LoggerFactory.getLogger(getClass))
/*
* Couchbase should know which ports are exposed for client, because this is how it exposes services.
* E.g. client ask only for on port - say 8091. And query service port is 8093. So client, won't ask for every port,
* instead CB will tell client on which port query service exposed, that's why CB …Run Code Online (Sandbox Code Playgroud)