Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support java.time.LocalDate on a row #74

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.simple</groupId>
<artifactId>jdub_2.12</artifactId>
<version>2.1.0</version>
<version>2.1.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>
Expand Down
36 changes: 29 additions & 7 deletions src/main/scala/com/simple/jdub/Row.scala
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down Expand Up @@ -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))

Expand All @@ -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].
Expand Down Expand Up @@ -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].
*/
Expand Down