Skip to content

Instantly share code, notes, and snippets.

@asaushkin
Created February 26, 2019 11:47
Show Gist options
  • Save asaushkin/94689e6a47b12af873aef70c1088f610 to your computer and use it in GitHub Desktop.
Save asaushkin/94689e6a47b12af873aef70c1088f610 to your computer and use it in GitHub Desktop.
Changes in the master branch of 'mist' that lead to compile-time error "value map is not a member of cats.effect.Resource"
diff --git a/mist.sbt b/mist.sbt
index 9c106f7..253ce39 100644
--- a/mist.sbt
+++ b/mist.sbt
@@ -88,9 +88,12 @@ lazy val master = project.in(file("mist/master"))
Library.chill,
Library.kafka, Library.pahoMqtt,
+ Library.doobieCore, Library.doobieH2, Library.doobieHikari,
+ Library.doobiePostgres, Library.doobieSpecs2,
+
Library.Akka.testKit % "test",
Library.Akka.http, Library.Akka.httpSprayJson, Library.Akka.httpTestKit % "test",
- Library.cats,
+ //Library.cats,
Library.dockerJava,
@@ -416,5 +419,6 @@ lazy val commonScalacOptions = Seq(
"-unchecked",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
+ "-Ypartial-unification",
"-deprecation"
)
diff --git a/mist/master/src/main/scala/io/hydrosphere/mist/master/store/HikariConnectionPool.scala b/mist/master/src/main/scala/io/hydrosphere/mist/master/store/HikariConnectionPool.scala
new file mode 100644
index 0000000..b950d2a
--- /dev/null
+++ b/mist/master/src/main/scala/io/hydrosphere/mist/master/store/HikariConnectionPool.scala
@@ -0,0 +1,31 @@
+package io.hydrosphere.mist.master.store
+
+import cats.effect._
+import cats.implicits._
+import doobie._
+import doobie.implicits._
+import doobie.hikari._
+
+import scala.concurrent.ExecutionContext
+
+object HikariConnectionPool {
+ // We need a ContextShift[IO] before we can construct a Transactor[IO]. The passed ExecutionContext
+ // is where nonblocking operations will be executed.
+ implicit val cs = IO.contextShift(ExecutionContext.global)
+
+ // Resource yielding a transactor configured with a bounded connect EC and an unbounded
+ // transaction EC. Everything will be closed and shut down cleanly after use.
+ val transactor: Resource[IO, HikariTransactor[IO]] =
+ for {
+ ce <- ExecutionContexts.fixedThreadPool[IO](32) // our connect EC
+ te <- ExecutionContexts.cachedThreadPool[IO] // our transaction EC
+ xa <- HikariTransactor.newHikariTransactor[IO](
+ "org.h2.Driver", // driver classname
+ "jdbc:h2:mem:test;DB_CLOSE_DELAY=-1", // connect URL
+ "sa", // username
+ "", // password
+ ce, // await connection here
+ te // execute JDBC operations here
+ )
+ } yield xa
+}
diff --git a/project/Library.scala b/project/Library.scala
index 58733ec..99b9c93 100644
--- a/project/Library.scala
+++ b/project/Library.scala
@@ -13,10 +13,18 @@ object Library {
val h2 = "com.h2database" % "h2" % "1.4.194"
val flyway = "org.flywaydb" % "flyway-core" % "4.1.1"
+ val doobieVersion = "0.6.0"
+ val doobieCore = "org.tpolecat" %% "doobie-core" % doobieVersion
+ val doobiePostgres = "org.tpolecat" %% "doobie-postgres" % doobieVersion
+ val doobieH2 = "org.tpolecat" %% "doobie-h2" % doobieVersion
+ val doobieHikari = "org.tpolecat" %% "doobie-hikari" % doobieVersion
+ val doobieSpecs2 = "org.tpolecat" %% "doobie-specs2" % doobieVersion
+
val pahoMqtt = "org.eclipse.paho" % "org.eclipse.paho.client.mqttv3" % "1.1.0"
val kafka = "org.apache.kafka" %% "kafka" % "0.10.2.0" exclude("log4j", "log4j") exclude("org.slf4j","slf4j-log4j12")
- val cats = "org.typelevel" %% "cats" % "0.9.0"
+ // There is `cats` dependency from doobie...
+ //val cats = "org.typelevel" %% "cats" % "0.9.0"
val scalaTest = "org.scalatest" %% "scalatest" % "3.0.1"
val junit = "junit" % "junit" % "4.12"
@asaushkin
Copy link
Author

There is same error in the issue tpolecat/doobie#790 here but unfortunally that decision is not fits the current problem.

Error:(22, 53) value map is not a member of cats.effect.Resource[cats.effect.IO,doobie.hikari.HikariTransactor[cats.effect.IO]]
      xa <- HikariTransactor.newHikariTransactor[IO](

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment