All Downloads are FREE. Search and download functionalities are using the official Maven repository.

harness.sql.ConnectionFactory.scala Maven / Gradle / Ivy

There is a newer version: 5.1.3
Show newest version
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