From cfa819c2ec70fde4704aae08af854d09ee1b5863 Mon Sep 17 00:00:00 2001 From: Richard Shurtz Date: Thu, 21 Sep 2023 16:32:02 -0700 Subject: [PATCH] Add ColReader for Timestamp --- .../src/main/scala/com/lucidchart/relate/ColReader.scala | 4 ++-- relate/src/test/scala/ColReaderTest.scala | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/relate/src/main/scala/com/lucidchart/relate/ColReader.scala b/relate/src/main/scala/com/lucidchart/relate/ColReader.scala index 94e81cd..e174cca 100644 --- a/relate/src/main/scala/com/lucidchart/relate/ColReader.scala +++ b/relate/src/main/scala/com/lucidchart/relate/ColReader.scala @@ -1,7 +1,6 @@ package com.lucidchart.relate -import java.nio.ByteBuffer -import java.sql.ResultSet +import java.sql.{ResultSet, Timestamp} import java.time.Instant import java.util.{Date, UUID} @@ -67,6 +66,7 @@ object ColReader { implicit val longReader: ColReader[Long] = optReader((col, rs) => rs.getLong(col)) implicit val shortReader: ColReader[Short] = optReader((col, rs) => rs.getShort(col)) implicit val stringReader: ColReader[String] = optReader((col, rs) => rs.getString(col)) + implicit val timeReader: ColReader[Timestamp] = optReader((col, rs) => rs.getTimestamp(col)) implicit val uuidReader: ColReader[UUID] = ColReader[UUID] { (col, row) => row.uuidOption(col) } diff --git a/relate/src/test/scala/ColReaderTest.scala b/relate/src/test/scala/ColReaderTest.scala index a725ac1..6cc4b6c 100644 --- a/relate/src/test/scala/ColReaderTest.scala +++ b/relate/src/test/scala/ColReaderTest.scala @@ -13,6 +13,7 @@ case class RecordA( byte: Byte, sqlDate: java.sql.Date, timestampDate: Date, + timestamp: Timestamp, instant: Instant, double: Double, int: Int, @@ -33,6 +34,7 @@ object RecordA extends Mockito { row[Byte]("byte"), row[java.sql.Date]("sqlDate"), row[Date]("timestampDate"), + row[Timestamp]("timestamp"), row[Instant]("instant"), row[Double]("double"), row[Int]("int"), @@ -55,6 +57,7 @@ object RecordA extends Mockito { rs.getByte("byte") returns (1: Byte) rs.getDate("sqlDate") returns (new java.sql.Date(10000)) rs.getTimestamp("timestampDate") returns (new Timestamp(timeMillis)) + rs.getTimestamp("timestamp") returns (new Timestamp(timeMillis)) rs.getTimestamp("instant") returns (new java.sql.Timestamp(timeMillis)) rs.getDouble("double") returns 1.1 rs.getInt("int") returns 10 @@ -75,6 +78,7 @@ case class RecordB( byte: Option[Byte], sqlDate: Option[java.sql.Date], timestampDate: Option[Date], + timestamp: Option[Timestamp], instant: Option[Instant], double: Option[Double], int: Option[Int], @@ -95,6 +99,7 @@ object RecordB extends Mockito { row.opt[Byte]("byte"), row.opt[java.sql.Date]("sqlDate"), row.opt[Date]("timestampDate"), + row.opt[Timestamp]("timestamp"), row.opt[Instant]("instant"), row.opt[Double]("double"), row.opt[Int]("int"), @@ -114,6 +119,7 @@ object RecordB extends Mockito { rs.getBytes("ba") returns null rs.getDate("sqlDate") returns null rs.getTimestamp("timestampDate") returns null + rs.getTimestamp("timestamp") returns null rs.getString("str") returns null rs.getBytes("uuid") returns null SqlRow(rs) @@ -147,6 +153,7 @@ class ColReaderTest extends Specification with Mockito { 1, new java.sql.Date(10000), new Date(mockedInstant.toEpochMilli), + new Timestamp(mockedInstant.toEpochMilli), mockedInstant, 1.1, 10, @@ -176,6 +183,7 @@ class ColReaderTest extends Specification with Mockito { None, None, None, + None, None ) } @@ -196,6 +204,7 @@ class ColReaderTest extends Specification with Mockito { Some(1), Some(new java.sql.Date(10000)), Some(new Date(mockedInstant.toEpochMilli)), + Some(new Timestamp(mockedInstant.toEpochMilli)), Some(mockedInstant), Some(1.1), Some(10),