Skip to content

Commit

Permalink
Support java.time.LocalDate on a row
Browse files Browse the repository at this point in the history
vanvlack committed Apr 16, 2020
1 parent 2205ed5 commit 24e5e2e
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@

<groupId>com.simple</groupId>
<artifactId>jdub_2.11</artifactId>
<version>1.5.0</version>
<version>1.5.1</version>
<name>Jdub for Scala ${scala.version}</name>
<url>https://github.com/SimpleFinance/jdub</url>
<description>Jdub is a Scala wrapper over JDBC.</description>
17 changes: 14 additions & 3 deletions src/main/scala/com/simple/jdub/Row.scala
Original file line number Diff line number Diff line change
@@ -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].
*/

0 comments on commit 24e5e2e

Please sign in to comment.