Fork me on GitHub
#sql
<
2022-11-24
>
hifumi12307:11:21

Trying to migrate to next.jdbc from clojure.java.jdbc, and I am wondering if there is something really basic that I am missing here. I am attempting to find an equivalent to :row-fn as follows.

(j/query ds
         ["SELECT c1 AS col FROM UNNEST(ARRAY['x', 'y', 'z'])"]
         {:row-fn :col})   
So far I have some up with this
(mapv :col (j/plan ds
                   ["SELECT c1 AS col FROM UNNEST(ARRAY['x', 'y', 'z'])"]
                   {:builder-fn rs/as-unqualified-lower-maps}))
But I'm wondering if there is a way to compose the builder-fn with :col so I can simply use j/execute! instead of mapping over a plan.

valerauko07:11:20

my first try would be using comp to compose the provided row-builder with :col

hifumi12308:11:35

I've tried that and I get an exception 😞 Then I referred to some documentation on differences between clojure.java.jdbc and next.jdbc. If I understood it correctly, I should be able to use something like (partial map :col) as a function over the record set, but that doesn't work either.

valerauko08:11:43

i think at this point it's quicker to just map :col than write your own builder haha

seancorfield10:11:09

next.jdbc.plan/select! is what you want

hifumi12316:11:37

Perfect! This gives me the exact functionality I need in a very concise way 🙂

1