This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-19
Channels
- # announcements (10)
- # aws (3)
- # aws-lambda (1)
- # babashka (24)
- # beginners (57)
- # boot (5)
- # calva (20)
- # chlorine-clover (3)
- # cider (14)
- # clj-kondo (37)
- # clojars (17)
- # clojure (200)
- # clojure-dev (40)
- # clojure-europe (9)
- # clojure-france (7)
- # clojure-gamedev (5)
- # clojure-hungary (4)
- # clojure-italy (8)
- # clojure-losangeles (2)
- # clojure-nl (9)
- # clojure-uk (97)
- # clojurebridge (1)
- # clojured (3)
- # clojuredesign-podcast (23)
- # clojurescript (13)
- # code-reviews (2)
- # component (22)
- # core-typed (7)
- # cursive (64)
- # datascript (12)
- # datomic (60)
- # emacs (6)
- # fulcro (54)
- # graalvm (11)
- # graphql (3)
- # hoplon (25)
- # jobs (1)
- # joker (85)
- # juxt (5)
- # kaocha (10)
- # klipse (8)
- # malli (2)
- # off-topic (36)
- # parinfer (1)
- # pathom (1)
- # re-frame (9)
- # reagent (4)
- # reitit (1)
- # remote-jobs (1)
- # shadow-cljs (24)
- # spacemacs (1)
- # sql (39)
- # tools-deps (10)
- # tree-sitter (18)
- # xtdb (18)
I have a Postgres query that should return a java.time.LocalDate
since my column is DATE
: https://jdbc.postgresql.org/documentation/head/8-date-time.html -- but instead I'm seeing java.sql.Date
as the class. I wonder if I have to do something special with next.jdbc?
(-> (jdbc/execute-one! DS ["select current_timestamp::date"])
:current_timestamp
class)
;=> java.sql.Date
Anyway, doing this:
(extend-protocol next.jdbc.result-set/ReadableColumn
java.sql.Date
(read-column-by-label [^java.sql.Date v label]
(.toLocalDate v))
(read-column-by-index [^java.sql.Date v rs-meta idx]
(.toLocalDate v)))
does the trick. But I'm confused on the whole casting of values that JDBC / next.jdbc does.
@orestis next.jdbc
doesn't do any casting by default -- it relies entirely on the JDBC driver. Whatever the driver gives you back (as an Object
) is what you get.
If you require the (optional) next.jdbc.date-time
namespace, then you get a bunch of coercions around date/time -- particularly useful for PostgreSQL since it sometimes doesn't do certain basic coercions. But bear in mind, loading those protocol extensions means you "buy in" for your whole application.
I see that JDBC has versions, is that a historical artifact and everyone is at the latest?
(and that ns is for inbound -- Clojure to JDBC -- coercions, not outbound)
Not sure what you mean about "JDBC has versions"?
> The PostgreSQL™ JDBC driver implements native support for the Java 8 Date and Time API (JSR-310) using JDBC 4.2.
No idea about PG -- it def. does some weird stuff. I added next.jdbc.date-time
because it would not do those coercions automatically.
Either way, next.jdbc
just passes objects back and forth to JDBC.
Right, which is not the call next.jdbc
makes.
next.jdbc
uses the single argument call because it has to be generic.
Right, which next.jdbc
cannot know in advance -- since it is a type from "user code" and not from the database schema.
Last question, on the ReadbleColunn protocol, when is the function with the column name called? In some light testing I only saw the version with the column Index called.
And also since it looks to be a global protocol, I can’t see how the name or index are useful. Unless you can customize this per call and I haven’t found out yet
That's explained in the docs somewhere...
(I'm eating breakfast so I can't look right now)
plan
uses just the column label. execute!
uses the column index and passes the result set metadata so you can look in the metadata for more information about the (JDBC) type of that column, as well as get its name etc.
(`plan` is deliberately restrictive so that it can be as fast as possible, so it avoids fetching result set metadata if possible)
NP. I looked in the docs once I'd finished (eggs over easy and maple pork links!).
Yum! Gotta love the options in California. I miss being in a Mediterranean climate. (Greek living in Denmark)
That was home-cooked 🙂
But, yeah, California has some awesome food options.
I will try to write a JDBC 101 because frankly the situation was really confusing to me when I started dealing with all those things :)
Happy to extend the docs with that, if you feel like contributing via a PR!