Fork me on GitHub
#sql
<
2019-08-13
>
Jakub Holý (HolyJak)11:08:06

@seancorfield I am sorry, I am looking at the docs and source of next.jdbc but fail to find how to access the raw ResultSet. Could you be so kind and point me in the right direction? (I want to call .getLong instead of the default .getObject, to try to get a timestamp as a number instead of a Date). I guess I could supply {:builder-fn my-builder} to plan, where my-builder returns my own implementation of RowBuilder. Is that correct? Is there a better way? Or perhaps it is easier to use JDBC directly...

dcj15:08:48

@holyjak Here is what I did to have sql timestamps returned differently:

(extend-protocol result-set/ReadableColumn

  java.sql.Timestamp

  (read-column-by-label ^java.time.ZonedDateTime [^java.sql.Timestamp v _]
    (time/zoned-date-time (time/instant v) "UTC"))
  (read-column-by-index ^java.time.ZonedDateTime [^java.sql.Timestamp v _2 _3]
    (time/zoned-date-time (time/instant v) "UTC"))
Could you just (.getLong v) above, or something similar to get what you want?

seancorfield16:08:03

@holyjak As @dcj suggested, you'd need to extend ReadableColumn to get the behavior you want. Another option is to extend RowBuilder and ResultSetBuilder to create a custom builder but you're taking on a lot more control in that approach.