Closed lemonteaa closed 6 years ago
The Jodatime conversion is triggered by clj-time.jdbc. It attempts to coerce dates coming back in results into Joda time objects:
(extend-protocol jdbc/IResultSetReadColumn
java.sql.Timestamp
(result-set-read-column [v _2 _3]
(tc/from-sql-time v))
java.sql.Date
(result-set-read-column [v _2 _3]
(tc/from-sql-date v))
java.sql.Time
(result-set-read-column [v _2 _3]
(org.joda.time.DateTime. v)))
; http://clojure.github.io/java.jdbc/#clojure.java.jdbc/ISQLValue
(extend-protocol jdbc/ISQLValue
org.joda.time.DateTime
(sql-value [v]
(tc/to-sql-time v)))
I updated the example to use JodaTime as follows:
(deftest test-message
(jdbc/with-db-transaction [t-conn *db*]
(jdbc/db-set-rollback-only! t-conn)
(let [timestamp (org.joda.time.DateTime. org.joda.time.DateTimeZone/UTC)]
(is (= 1 (db/save-message!
t-conn
{:name "Bob"
:message "Hello, World"
:timestamp timestamp}
{:connection t-conn})))
(is (=
{:name "Bob"
:message "Hello, World"
:timestamp timestamp}
(-> (db/get-messages t-conn {})
(first)
(select-keys [:name :message :timestamp])))))))
Thanks for the explanation! (and code search I suppose 😉 ) It works now 👍
It seems like tests from repository and tests from tutorial are'nt syncronised. I've got hard times to figure out what is happening, then repo version saved my life. Please update section "Adding some tests" in guestbook application like in this line
Thanks for the heads up, updated the docs accordingly.
When following the guestbook tutorial, the unit test in the section 'Adding some tests' failed with the following message:
Does the db library do automatic conversion to/from Jodatime somewhere? (Just a wild guess)