harness.sql.ConnectionFactory.scala Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of harness-sql_3 Show documentation
Show all versions of harness-sql_3 Show documentation
Miscellaneous libraries/utilities for Scala.
package harness.sql
import harness.sql.error.ConnectionError
import harness.zio.*
import java.sql.{Connection, DriverManager}
import zio.*
final class ConnectionFactory private (
private[sql] val getJDBCConnection: ZIO[Scope, ConnectionError, JDBCConnection],
)
object ConnectionFactory {
private def wrapUnsafe(get: => Connection): ConnectionFactory =
new ConnectionFactory(ZIO.acquireAutoClosable(ZIO.attempt(get)).mapBoth(ConnectionError(_), JDBCConnection(_)))
def apply(url: String): ConnectionFactory = wrapUnsafe(DriverManager.getConnection(url))
def apply(url: String, user: String, password: String): ConnectionFactory = wrapUnsafe(DriverManager.getConnection(url, user, password))
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy