Skip to content

Commit

Permalink
fix: ConfigReader for TransactionIsolation
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubjanecek committed Oct 22, 2019
1 parent bc414f9 commit c4a8d73
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package com.avast.sst.doobie.pureconfig

import cats.syntax.either._
import com.avast.sst.doobie.DoobieHikariConfig
import doobie.enum.TransactionIsolation
import pureconfig.ConfigReader
import pureconfig.generic.semiauto.{deriveEnumerationReader, deriveReader}
import pureconfig.error.CannotConvert
import pureconfig.generic.semiauto.deriveReader

trait ConfigReaders {

implicit val transactionIsolationReader: ConfigReader[TransactionIsolation] = deriveEnumerationReader
implicit val transactionIsolationReader: ConfigReader[TransactionIsolation] = ConfigReader[String].emap {
case "TRANSACTION_NONE" => TransactionIsolation.TransactionNone.asRight
case "TRANSACTION_READ_UNCOMMITTED" => TransactionIsolation.TransactionReadUncommitted.asRight
case "TRANSACTION_READ_COMMITTED" => TransactionIsolation.TransactionReadCommitted.asRight
case "TRANSACTION_REPEATABLE_READ" => TransactionIsolation.TransactionRepeatableRead.asRight
case "TRANSACTION_SERIALIZABLE" => TransactionIsolation.TransactionSerializable.asRight
case unknown => Left(CannotConvert(unknown, "TransactionIsolation", "unknown value"))
}

implicit val configReader: ConfigReader[DoobieHikariConfig] = deriveReader

Expand Down

0 comments on commit c4a8d73

Please sign in to comment.