diff options
author | vlad <vlad@driver.xyz> | 2018-01-18 15:42:50 -0800 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2018-01-18 15:42:50 -0800 |
commit | 1cda54833c6083020ba20944319e6fb03ecfd419 (patch) | |
tree | 58c32a5791ba1e318b19b4c19ecc9f51e70e8726 /src/main/scala/xyz/driver/pdsuicommon/db | |
parent | 39d3c6bf58d5e386fe0f354e16f487f316e86774 (diff) | |
download | rest-query-1cda54833c6083020ba20944319e6fb03ecfd419.tar.gz rest-query-1cda54833c6083020ba20944319e6fb03ecfd419.tar.bz2 rest-query-1cda54833c6083020ba20944319e6fb03ecfd419.zip |
Removing Quill completely from the pdsui-common
Diffstat (limited to 'src/main/scala/xyz/driver/pdsuicommon/db')
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/db/PostgresContext.scala | 72 |
1 files changed, 0 insertions, 72 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/db/PostgresContext.scala b/src/main/scala/xyz/driver/pdsuicommon/db/PostgresContext.scala deleted file mode 100644 index 0098a64..0000000 --- a/src/main/scala/xyz/driver/pdsuicommon/db/PostgresContext.scala +++ /dev/null @@ -1,72 +0,0 @@ -package xyz.driver.pdsuicommon.db - -import java.io.Closeable -import java.time.{LocalDateTime, ZoneOffset} -import java.util.UUID -import java.util.concurrent.Executors -import javax.sql.DataSource - -import io.getquill._ -import xyz.driver.pdsuicommon.concurrent.MdcExecutionContext -import xyz.driver.pdsuicommon.db.PostgresContext.Settings -import xyz.driver.pdsuicommon.domain.UuidId -import xyz.driver.pdsuicommon.logging._ - -import scala.concurrent.ExecutionContext -import scala.util.control.NonFatal -import scala.util.{Failure, Success, Try} - -object PostgresContext extends PhiLogging { - - final case class Settings(connection: com.typesafe.config.Config, - connectionAttemptsOnStartup: Int, - threadPoolSize: Int) - - def apply(settings: Settings): PostgresContext = { - // Prevent leaking credentials to a log - Try(JdbcContextConfig(settings.connection).dataSource) match { - case Success(dataSource) => new PostgresContext(dataSource, settings) - case Failure(NonFatal(e)) => - logger.error(phi"Can not load dataSource, error: ${Unsafe(e.getClass.getName)}") - throw new IllegalArgumentException("Can not load dataSource from config. Check your database and config", e) - } - } - -} - -class PostgresContext(val dataSource: DataSource with Closeable, settings: Settings) - extends PostgresJdbcContext[SnakeCase](dataSource) with TransactionalContext { - - private val tpe = Executors.newFixedThreadPool(settings.threadPoolSize) - - implicit val executionContext: ExecutionContext = { - val orig = ExecutionContext.fromExecutor(tpe) - MdcExecutionContext.from(orig) - } - - override def close(): Unit = { - super.close() - tpe.shutdownNow() - } - - /** - * Usable for QueryBuilder's extractors - */ - def timestampToLocalDateTime(timestamp: java.sql.Timestamp): LocalDateTime = { - LocalDateTime.ofInstant(timestamp.toInstant, ZoneOffset.UTC) - } - - implicit def encodeUuidId[T] = MappedEncoding[UuidId[T], String](_.toString) - implicit def decodeUuidId[T] = MappedEncoding[String, UuidId[T]] { uuid => - UuidId[T](UUID.fromString(uuid)) - } - - def decodeOptUuidId[T] = MappedEncoding[Option[String], Option[UuidId[T]]] { - case Some(x) => Option(x).map(y => UuidId[T](UUID.fromString(y))) - case None => None - } - - implicit def decodeUuid[T] = MappedEncoding[String, UUID] { uuid => - UUID.fromString(uuid) - } -} |