From 78830d002d30cc6c3c2ecb291a2b244f7093efb6 Mon Sep 17 00:00:00 2001 From: Chris Van Vlack Date: Thu, 16 Apr 2020 17:29:37 -0500 Subject: [PATCH] Support `java.time.LocalDate` on a row --- pom.xml | 2 +- src/main/scala/com/simple/jdub/Row.scala | 36 +++++++++++++++++++----- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/pom.xml b/pom.xml index 954709f..aeabc29 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.simple jdub_2.12 - 2.1.0 + 2.1.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 7637fce..d8363c8 100644 --- a/src/main/scala/com/simple/jdub/Row.scala +++ b/src/main/scala/com/simple/jdub/Row.scala @@ -1,11 +1,23 @@ package com.simple.jdub -import org.joda.time.{DateTime, DateTimeZone} +import org.joda.time.DateTime +import org.joda.time.DateTimeZone -import java.io.{InputStream, Reader} +import java.io.InputStream +import java.io.Reader import java.net.URL -import java.sql.{Blob, Clob, Date, NClob, Ref, ResultSet, SQLXML, Time, Timestamp} -import java.time.{Instant, LocalDateTime} +import java.sql.Blob +import java.sql.Clob +import java.sql.Date +import java.sql.NClob +import java.sql.Ref +import java.sql.ResultSet +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 /** @@ -116,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)) @@ -143,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]. @@ -175,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]. */