Recently I started learning doobie but I couldn't create a hikari transactor without error. I'm using mysql, Intellij-Idea.
This is my build.sbt file
name := "doobie"
version := "0.1"
//scalaVersion := "2.13.1"
scalacOptions += "-Ypartial-unification" // 2.11.9+
libraryDependencies ++= {
lazy val doobieVersion = "0.8.4"
Seq(
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"org.tpolecat" %% "doobie-quill" % doobieVersion,
"org.tpolecat" %% "doobie-specs2" % doobieVersion,
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % "test",
"mysql" % "mysql-connector-java" % "8.0.17",
"org.slf4j" % "slf4j-api" % "1.7.5",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
}
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)
This is my Connection.scala file
import cats.effect.IO
import com.zaxxer.hikari.{HikariConfig, HikariDataSource}
import doobie.hikari.HikariTransactor
trait Connection {
val config = new HikariConfig()
config.setJdbcUrl("jdbc:mysql://localhost:quill_demo")
config.setUsername("admin")
config.setPassword("password")
config.setMaximumPoolSize(5)
val transactor: IO[HikariTransactor[IO]] =
IO.pure(HikariTransactor.apply[IO](new HikariDataSource(config)))
}
The problem is in above file IO.pure(HikariTransactor.apply[IO](new HikariDataSource(config)))
statement gives error. Here 3 of last closed braces gives 3 errors as below.
No implicit arguments of type: ContextShift[IO]
Unspecified value parameters: connectEC: ExecutionContext, transactEC: ExecutionContext
No implicits found for parameter evidence$2: ContextShift[IO]
All I want to know, How to do this correctly.
After I change the versions of dependencies as follows, I could solve all errors.
name := "doobie"
version := "0.1"
//scalaVersion := "2.13.1"
scalacOptions += "-Ypartial-unification"
libraryDependencies ++= {
lazy val doobieVersion = "0.5.4"
Seq(
"org.tpolecat" %% "doobie-core" % doobieVersion,
"org.tpolecat" %% "doobie-h2" % doobieVersion,
"org.tpolecat" %% "doobie-hikari" % doobieVersion,
"org.tpolecat" %% "doobie-quill" % doobieVersion,
"org.tpolecat" %% "doobie-specs2" % doobieVersion,
"org.tpolecat" %% "doobie-scalatest" % doobieVersion % "test",
"mysql" % "mysql-connector-java" % "5.1.34",
"org.slf4j" % "slf4j-api" % "1.7.5",
"ch.qos.logback" % "logback-classic" % "1.0.9"
)
}
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
)