From 24e5e2e13cd3ab594617a19a05e86e6a9becd0d5 Mon Sep 17 00:00:00 2001 From: Chris Van Vlack Date: Thu, 16 Apr 2020 17:24:15 -0500 Subject: [PATCH] Support `java.time.LocalDate` on a row --- pom.xml | 2 +- src/main/scala/com/simple/jdub/Row.scala | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f9071b6..c66a17e 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.simple jdub_2.11 - 1.5.0 + 1.5.1 Jdub for Scala ${scala.version} https://github.com/SimpleFinance/jdub Jdub is a Scala wrapper over JDBC. diff --git a/src/main/scala/com/simple/jdub/Row.scala b/src/main/scala/com/simple/jdub/Row.scala index 0f68b39..d8363c8 100644 --- a/src/main/scala/com/simple/jdub/Row.scala +++ b/src/main/scala/com/simple/jdub/Row.scala @@ -16,6 +16,7 @@ import java.sql.SQLXML import java.sql.Time import java.sql.Timestamp import java.time.Instant +import java.time.LocalDate import java.time.LocalDateTime import java.util.UUID @@ -127,12 +128,12 @@ class Row(rs: ResultSet) { def bigDecimal(name: String): Option[BigDecimal] = extract(rs.getBigDecimal(name)).map { scala.math.BigDecimal(_) } /** - * Extract the value at the given offset as an Option[Array[Byte]]. + * Extract the value at the given offset as an `Option[Array[Byte]]`. */ def bytes(index: Int): Option[Array[Byte]] = extract(rs.getBytes(index + 1)) /** - * Extract the value with the given name as an Option[Array[Byte]]. + * Extract the value with the given name as an `Option[Array[Byte]]`. */ def bytes(name: String): Option[Array[Byte]] = extract(rs.getBytes(name)) @@ -154,7 +155,7 @@ class Row(rs: ResultSet) { /** * Extract the value with the given name as an Option[Time]. */ - def time(name: String) = extract(rs.getTime(name)) + def time(name: String): Option[Time] = extract(rs.getTime(name)) /** * Extract the value at the given offset as an Option[Timestamp]. @@ -186,6 +187,16 @@ class Row(rs: ResultSet) { */ def localDateTime(name: String): Option[LocalDateTime] = timestamp(name).map(_.toLocalDateTime) + /** + * Extract the value at the given offset as an Option[LocalDate]. + */ + def localDate(index: Int): Option[LocalDate] = localDateTime(index).map(_.toLocalDate) + + /** + * Extract the value with the given name as an Option[LocalDate]. + */ + def localDate(name: String): Option[LocalDate] = localDateTime(name).map(_.toLocalDate) + /** * Extract the value with the given name as an Option[DateTime]. */