I want to get the hikari transactor setup to act just like the standard transactor
val xa = HikariTransactor.newHikariTransactor[IO](
"com.mysql.jdbc.Driver",
JdbcUrl,
Username,
Password
)
sql"""select DISTINCT gcpProject FROM JobStatus"""
.query[String] // Query0[String]
.stream // Stream[ConnectionIO, String]
.take(5) // Stream[ConnectionIO, String]
.compile.toList // ConnectionIO[List[String]]
.transact(xa) // IO[List[String]]
.unsafeRunSync // List[String]
.foreach(println) // Unit
Unfortunately this gives me:
Type mismatch, expected: tansactor.Transactor[NotInferedM], actual: IO[hikari.HikariTransactor[IO]]
Any ideas on how can can get this working properly?
Just a note that the previous solution used a single connection each time and works correctly:
val xa = Transactor.fromDriverManager[IO](
"com.mysql.jdbc.Driver",
JdbcUrl,
Username,
Password
)
But I could really use a connection pool.
Okay after a bunch of testing I finally worked it out!
I'll post my solution here just in case someone else finds this helpful:
val config = new HikariConfig()
config.setJdbcUrl(JdbcUrl)
config.setUsername(Username)
config.setPassword(Password)
config.setMaximumPoolSize(databaseConnectionPoolSize)
val DbTransactor: IO[HikariTransactor[IO]] =
IO.pure(HikariTransactor.apply[IO](new HikariDataSource(config)))
sql"""select DISTINCT gcpProject FROM JobStatus"""
.query[String]
.stream
.take(5)
.compile.toList
val prog = for {
xa <- transactor
result <- query.transact(xa)
} yield result
prog.unsafeRunSync()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With