Skip to content

Commit 78830d0

Browse files
committed
Support java.time.LocalDate on a row
1 parent c240e8a commit 78830d0

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>com.simple</groupId>
88
<artifactId>jdub_2.12</artifactId>
9-
<version>2.1.0</version>
9+
<version>2.1.1</version>
1010
<name>Jdub for Scala ${scala.version}</name>
1111
<url>https://github.com/SimpleFinance/jdub</url>
1212
<description>Jdub is a Scala wrapper over JDBC.</description>

src/main/scala/com/simple/jdub/Row.scala

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
package com.simple.jdub
22

3-
import org.joda.time.{DateTime, DateTimeZone}
3+
import org.joda.time.DateTime
4+
import org.joda.time.DateTimeZone
45

5-
import java.io.{InputStream, Reader}
6+
import java.io.InputStream
7+
import java.io.Reader
68
import java.net.URL
7-
import java.sql.{Blob, Clob, Date, NClob, Ref, ResultSet, SQLXML, Time, Timestamp}
8-
import java.time.{Instant, LocalDateTime}
9+
import java.sql.Blob
10+
import java.sql.Clob
11+
import java.sql.Date
12+
import java.sql.NClob
13+
import java.sql.Ref
14+
import java.sql.ResultSet
15+
import java.sql.SQLXML
16+
import java.sql.Time
17+
import java.sql.Timestamp
18+
import java.time.Instant
19+
import java.time.LocalDate
20+
import java.time.LocalDateTime
921
import java.util.UUID
1022

1123
/**
@@ -116,12 +128,12 @@ class Row(rs: ResultSet) {
116128
def bigDecimal(name: String): Option[BigDecimal] = extract(rs.getBigDecimal(name)).map { scala.math.BigDecimal(_) }
117129

118130
/**
119-
* Extract the value at the given offset as an Option[Array[Byte]].
131+
* Extract the value at the given offset as an `Option[Array[Byte]]`.
120132
*/
121133
def bytes(index: Int): Option[Array[Byte]] = extract(rs.getBytes(index + 1))
122134

123135
/**
124-
* Extract the value with the given name as an Option[Array[Byte]].
136+
* Extract the value with the given name as an `Option[Array[Byte]]`.
125137
*/
126138
def bytes(name: String): Option[Array[Byte]] = extract(rs.getBytes(name))
127139

@@ -143,7 +155,7 @@ class Row(rs: ResultSet) {
143155
/**
144156
* Extract the value with the given name as an Option[Time].
145157
*/
146-
def time(name: String) = extract(rs.getTime(name))
158+
def time(name: String): Option[Time] = extract(rs.getTime(name))
147159

148160
/**
149161
* Extract the value at the given offset as an Option[Timestamp].
@@ -175,6 +187,16 @@ class Row(rs: ResultSet) {
175187
*/
176188
def localDateTime(name: String): Option[LocalDateTime] = timestamp(name).map(_.toLocalDateTime)
177189

190+
/**
191+
* Extract the value at the given offset as an Option[LocalDate].
192+
*/
193+
def localDate(index: Int): Option[LocalDate] = localDateTime(index).map(_.toLocalDate)
194+
195+
/**
196+
* Extract the value with the given name as an Option[LocalDate].
197+
*/
198+
def localDate(name: String): Option[LocalDate] = localDateTime(name).map(_.toLocalDate)
199+
178200
/**
179201
* Extract the value with the given name as an Option[DateTime].
180202
*/

0 commit comments

Comments
 (0)