Bug fix examples for SettableParameter and ReadableColumn
This commit is contained in:
parent
c246c5db6f
commit
eda2c4c270
2 changed files with 9 additions and 4 deletions
|
|
@ -32,13 +32,13 @@ This can be extended to any Clojure data type, to provide a customized way to ad
|
||||||
```clojure
|
```clojure
|
||||||
(extend-protocol p/SettableParameter
|
(extend-protocol p/SettableParameter
|
||||||
java.time.Instant
|
java.time.Instant
|
||||||
(set-parameter [^java.time.Instant v ^PreparedStatement s ^long i]
|
(set-parameter [^java.time.Instant v ^PreparedStatement ps ^long i]
|
||||||
(.setTimestamp ps i (java.sql.Timestamp/from v)))
|
(.setTimestamp ps i (java.sql.Timestamp/from v)))
|
||||||
java.time.LocalDate
|
java.time.LocalDate
|
||||||
(set-parameter [^java.time.LocalDate v ^PreparedStatement s ^long i]
|
(set-parameter [^java.time.LocalDate v ^PreparedStatement ps ^long i]
|
||||||
(.setTimestamp ps i (java.sql.Timestamp/valueOf (.atStartOfDay v))))
|
(.setTimestamp ps i (java.sql.Timestamp/valueOf (.atStartOfDay v))))
|
||||||
java.time.LocalDateTime
|
java.time.LocalDateTime
|
||||||
(set-parameter [^java.time.LocalDateTime v ^PreparedStatement s ^long i]
|
(set-parameter [^java.time.LocalDateTime v ^PreparedStatement ps ^long i]
|
||||||
(.setTimestamp ps i (java.sql.Timestamp/valueOf v))))
|
(.setTimestamp ps i (java.sql.Timestamp/valueOf v))))
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -73,10 +73,15 @@ In addition, inside `plan`, as each value is looked up by name in the current st
|
||||||
|
|
||||||
The default implementation of this protocol is for these two functions to return `nil` as `nil`, a `Boolean` value as a canonical `true` or `false` value (unfortunately, JDBC drivers cannot be relied on to return unique values here!), and for all other objects to be returned as-is.
|
The default implementation of this protocol is for these two functions to return `nil` as `nil`, a `Boolean` value as a canonical `true` or `false` value (unfortunately, JDBC drivers cannot be relied on to return unique values here!), and for all other objects to be returned as-is.
|
||||||
|
|
||||||
`next.jdbc` makes no assumptions beyond `nil` and `Boolean`, but common extensions here could include converting `java.sql.Timestamp` to `java.time.Instant` for example:
|
`next.jdbc` makes no assumptions beyond `nil` and `Boolean`, but common extensions here could include converting `java.sql.Date` to `java.time.LocalDate` and `java.sql.Timestamp` to `java.time.Instant` for example:
|
||||||
|
|
||||||
```clojure
|
```clojure
|
||||||
(extend-protocol rs/ReadableColumn
|
(extend-protocol rs/ReadableColumn
|
||||||
|
java.sql.Date
|
||||||
|
(read-column-by-label ^java.time.LocalDate [^java.sql.Date v _]
|
||||||
|
(.toLocalDate v))
|
||||||
|
(read-column-by-index ^java.time.LocalDate [^java.sql.Date v _2 _3]
|
||||||
|
(.toLocalDate v))
|
||||||
java.sql.Timestamp
|
java.sql.Timestamp
|
||||||
(read-column-by-label ^java.time.Instant [^java.sql.Timestamp v _]
|
(read-column-by-label ^java.time.Instant [^java.sql.Timestamp v _]
|
||||||
(.toInstant v))
|
(.toInstant v))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue