Cleanup and env file
This commit is contained in:
@@ -2,9 +2,6 @@ package db
|
||||
|
||||
import cats.effect.{Async, IO}
|
||||
import doobie.Transactor
|
||||
import pureconfig._
|
||||
import pureconfig.generic.auto._
|
||||
import pureconfig.error.ConfigReaderFailures
|
||||
|
||||
import java.net.URI
|
||||
import scala.util.Try
|
||||
@@ -12,8 +9,12 @@ import scala.util.Try
|
||||
case class PostgresConfig(url: String, username: String, password: String)
|
||||
|
||||
object DBConnection {
|
||||
private def getDbName = sys.env.getOrElse("POSTGRES_DB", "")
|
||||
private def getDbUser = sys.env.getOrElse("POSTGRES_USER", "")
|
||||
private def getDbPassword = sys.env.getOrElse("POSTGRES_PASSWORD", "")
|
||||
|
||||
private def getDatabaseUrl: String =
|
||||
sys.env.getOrElse("DATABASE_URL", "postgres://postgres:mysecretpassword@postgres:5432/weather-tool")
|
||||
sys.env.getOrElse("DATABASE_URL", s"postgres://${getDbUser}:${getDbPassword}@postgres:5432/${getDbName}")
|
||||
|
||||
private def parseUrl(url: String): Either[String, PostgresConfig] = {
|
||||
Try {
|
||||
@@ -24,8 +25,6 @@ object DBConnection {
|
||||
val username = raw.getUserInfo.split(":")(0)
|
||||
val password = raw.getUserInfo.split(":")(1)
|
||||
|
||||
println(s"n: $name u: $username, p: $password, url: $url")
|
||||
|
||||
PostgresConfig(dbUrl, username, password)
|
||||
}.toEither.left.map(_.getMessage)
|
||||
}
|
||||
@@ -41,24 +40,4 @@ object DBConnection {
|
||||
case Left(error) => IO.raiseError(new RuntimeException(s"Failed to parse DATABASE_URL: $error"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//case class PostgresConfig(url: String, username: String, password: String)
|
||||
|
||||
//object DBConnection {
|
||||
// private def loadPostgresConfig: Either[ConfigReaderFailures, PostgresConfig] = {
|
||||
// ConfigSource.resources("postgres.conf").load[PostgresConfig]
|
||||
// }
|
||||
//
|
||||
// def transactor[F[_] : Async]: IO[Transactor[F]] = {
|
||||
// loadPostgresConfig match {
|
||||
// case Right(config) => IO(Transactor.fromDriverManager[F](
|
||||
// "org.postgresql.Driver",
|
||||
// config.url,
|
||||
// config.username,
|
||||
// config.password
|
||||
// ))
|
||||
// case Left(errors) => IO.raiseError(new RuntimeException(s"Failed to load config: $errors"))
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
}
|
||||
Reference in New Issue
Block a user