hugsql

sandbags 2017-12-30T00:04:16.000050Z

I am sure I am doing something daft but… I am using sqlite in development and finding that Hugsql appears to be returning timestamp column values as strings rather than date objects of some kind. A quick google hasn't rustled anything up.

sandbags 2017-12-30T00:04:33.000010Z

Anyone know what I might obviously have missed here?

2017-12-30T05:09:06.000063Z

@sandbags have you tried using jdbc/query directly to see if strings are also returned? It’s usually the JDBC driver that does the marshalling/unmarshalling

sandbags 2017-12-30T10:24:19.000065Z

@rymndhng good idea

sandbags 2017-12-30T12:03:58.000051Z

So, yes, it seems like they are coming back as strings from jdbc/query

sandbags 2017-12-30T12:04:04.000060Z

this seems a might odd to me

udit 2017-12-30T17:36:07.000076Z

Thanks @admay & @jmayaalv. There was something else going wrong and not the queries 🙂

udit 2017-12-30T17:37:09.000120Z

@sandbags if you want a way around it you can probably do something as follows:

(extend-protocol jdbc/IResultSetReadColumn
  ;; all SQL timestamp cols returned as Java longs
  Timestamp
  (result-set-read-column [ts _ _]
    (.getTime ^Timestamp ts))

  ;; all SQL date cols returned as longs
  Date
  (result-set-read-column [ts _ _]
    (.getTime ^Date ts)))

udit 2017-12-30T17:37:39.000017Z

This will convert your date/timestamp fields into long (Or whatever you want them to be)

udit 2017-12-30T17:38:12.000057Z

You can read more about this here: http://clojure-doc.org/articles/ecosystem/java_jdbc/using_sql.html