diff options
author | vlad <vlad@driver.xyz> | 2017-06-15 17:10:09 -0700 |
---|---|---|
committer | vlad <vlad@driver.xyz> | 2017-06-15 17:10:09 -0700 |
commit | c1993e0f834cb4e0ccfd1dd54610ffe50de60238 (patch) | |
tree | 209224884296687c318041f7eca24f9002eee82c | |
parent | 7b8ac40ab6501ec53c5a55962fe4a3d54666ae8d (diff) | |
download | rest-query-c1993e0f834cb4e0ccfd1dd54610ffe50de60238.tar.gz rest-query-c1993e0f834cb4e0ccfd1dd54610ffe50de60238.tar.bz2 rest-query-c1993e0f834cb4e0ccfd1dd54610ffe50de60238.zip |
Added `optionDecoder` to SqlContext
-rw-r--r-- | src/main/scala/xyz/driver/pdsuicommon/db/SqlContext.scala | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/main/scala/xyz/driver/pdsuicommon/db/SqlContext.scala b/src/main/scala/xyz/driver/pdsuicommon/db/SqlContext.scala index 376956a..860629b 100644 --- a/src/main/scala/xyz/driver/pdsuicommon/db/SqlContext.scala +++ b/src/main/scala/xyz/driver/pdsuicommon/db/SqlContext.scala @@ -9,6 +9,7 @@ import com.typesafe.config.Config import io.getquill._ import xyz.driver.pdsuicommon.concurrent.MdcExecutionContext import xyz.driver.pdsuicommon.db.SqlContext.Settings +import xyz.driver.pdsuicommon.error.IncorrectIdException import xyz.driver.pdsuicommon.logging.{PhiLogging, Unsafe} import scala.concurrent.ExecutionContext @@ -59,6 +60,31 @@ class SqlContext(dataSource: DataSource with Closeable, settings: Settings) tpe.shutdownNow() } + /** + * Overrode, because Quill JDBC optionDecoder pass null inside decoders. + * If custom decoder don't have special null handler, it will failed. + * + * @see https://github.com/getquill/quill/issues/535 + */ + implicit override def optionDecoder[T](implicit d: Decoder[T]): Decoder[Option[T]] = + decoder( + sqlType = d.sqlType, + row => index => { + try { + val res = d(index - 1, row) + if (row.wasNull) { + None + } + else { + Some(res) + } + } catch { + case _: NullPointerException => None + case _: IncorrectIdException => None + } + } + ) + final implicit class LocalDateTimeDbOps(val left: LocalDateTime) { // scalastyle:off |