In my code I need to create a database and create some tables in it using cats.effect. The code as following,
def createTable[F[_]: Async]: Resource[F, ResultSet] = {
val createTableQuery = "CREATE TABLE IF NOT EXISTS warehouses (\n"
+ " id integer PRIMARY KEY,\n"
+ " name text NOT NULL,\n"
+ " capacity real\n"
+ ");";
for {
mutex <- Resource.eval(Mutex[F])
connection <- Resource.fromAutoCloseable(Async[F].blocking {
DriverManager.getConnection(s"jdbc:sqlite:/tmp/db/test.sqlite")
})
rs <-
Resource
.fromAutoCloseable {
mutex.lock.surround {
Async[F].blocking {
connection.prepareStatement(
createTableQuery
)
}
}
}
}yield{
rs.executeQuery()
}
}
But unfortunately, the database not creating and I found out that its not execute the DriverManager.getConnection(s"jdbc:sqlite:/tmp/db/test.sqlite") part. Can I know why it's not executing?
method called as below,
createTable[IO].use{
rs => IO(rs)
}