Fork me on GitHub
#sql
<
2022-07-18
>
mwolf22:07:35

I believe this should do the right thing, but I'm getting a vector of just one record repeated ... where am I being stupid?

(transduce (take 32) conj [] (next.jdbc/plan blah ["select distinct stuff from somewhere"]))

seancorfield22:07:41

You are not processing the rows -- I think the docs specifically warn against that not working as expected.

mwolf22:07:39

is there an example somewhere of using transduce with a sql query?

mwolf22:07:52

cool -- thanks. apologies, I had read the docs months ago, was just picking up this code again. nice library, btw -- thanks!

seancorfield22:07:48

I don't know that there's an explicit warning about just trying to pour unprocessed rows into a collection -- that could perhaps be made clearer in the docs -- but the bottom line is that the "row" you get from plan is not a Clojure data structure (per the docs) which you must process in your reducing function to produce Clojure data from.

seancorfield22:07:49

(and the underlying thing that not-a-Clojure-data-structure wraps is a mutable Java object -- which is why you seemed to get a repeated row in your results)

mwolf22:07:37

yeah, I recall that now that you mention it. previously had a call to extract the fields I needed per row but removed that code when I was hacking about. will put it back in and things should be fine. thanks again --

1