Skip to content

Instantly share code, notes, and snippets.

@martinlechner1
Last active October 25, 2019 08:10
Show Gist options
  • Save martinlechner1/d4ce271ce96d485db01496add6a1b58f to your computer and use it in GitHub Desktop.
Save martinlechner1/d4ce271ce96d485db01496add6a1b58f to your computer and use it in GitHub Desktop.
private def buildTransactor(c: Connection): Resource[IO, Transactor[IO]] =
Blocker[IO].map { b =>
Transactor.fromConnection[IO](c, b)
}
private def prestoTransactor(): Resource[IO, Transactor[IO]] =
Resource.fromAutoCloseable[IO, Connection] {
IO.fromTry(Try {
val url = "jdbc:presto://your-presto-jdbc-url"
val properties = new Properties()
properties.setProperty("user", System.getenv("PRESTO_USER"))
properties.setProperty("password", System.getenv("PRESTO_PW"))
val connection = DriverManager.getConnection(url, properties)
connection.setSchema("your_schema")
connection.setAutoCommit(true)
connection
})
}
.flatMap(buildTransactor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment