-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Encoders/Decoders for java.time._
- Loading branch information
1 parent
1eb40fa
commit e4dabad
Showing
9 changed files
with
82 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
quill-jdbc/src/main/scala/io/getquill/context/jdbc/PostgresDateTimeDecoders.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package io.getquill.context.jdbc | ||
|
||
import java.time.{ LocalDate, LocalDateTime, LocalTime, OffsetDateTime } | ||
|
||
trait PostgresDateTimeDecoders { | ||
self: JdbcContextBase[_, _] with Decoders => | ||
// Taken from https://jdbc.postgresql.org/documentation/head/8-date-time.html | ||
|
||
override implicit val localDateDecoder: Decoder[LocalDate] = | ||
decoder( | ||
(index, row) => | ||
row.getObject(index, classOf[LocalDate]) | ||
) | ||
|
||
implicit val localTimeDecoder: Decoder[LocalTime] = | ||
decoder( | ||
(index, row) => | ||
row.getObject(index, classOf[LocalTime]) | ||
) | ||
|
||
override implicit val localDateTimeDecoder: Decoder[LocalDateTime] = | ||
decoder( | ||
(index, row) => | ||
row.getObject(index, classOf[LocalDateTime]) | ||
) | ||
|
||
implicit val offsetDateTimeDecoder: Decoder[OffsetDateTime] = | ||
decoder( | ||
(index, row) => | ||
row.getObject(index, classOf[OffsetDateTime]) | ||
) | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
quill-jdbc/src/main/scala/io/getquill/context/jdbc/PostgresDateTimeEncoders.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package io.getquill.context.jdbc | ||
|
||
import java.time.{ LocalDate, LocalDateTime, LocalTime, OffsetDateTime } | ||
|
||
trait PostgresDateTimeEncoders { | ||
self: JdbcContextBase[_, _] with Encoders => | ||
// Taken from https://jdbc.postgresql.org/documentation/head/8-date-time.html | ||
|
||
private[this] def objectEncoder[T]: Encoder[T] = encoder( | ||
java.sql.Types.OTHER, | ||
(index, value, row) => row.setObject(index, value) | ||
) | ||
|
||
override implicit val localDateEncoder: Encoder[LocalDate] = objectEncoder[LocalDate] | ||
implicit val localTimeEncoder: Encoder[LocalTime] = objectEncoder[LocalTime] | ||
override implicit val localDateTimeEncoder: Encoder[LocalDateTime] = objectEncoder[LocalDateTime] | ||
implicit val offsetDateTimeEncoder: Encoder[OffsetDateTime] = objectEncoder[OffsetDateTime] | ||
} |