This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-25
Channels
- # babashka (77)
- # beginners (107)
- # calva (20)
- # cider (2)
- # clj-kondo (7)
- # clojure (63)
- # clojure-australia (2)
- # clojure-europe (75)
- # clojure-germany (10)
- # clojure-italy (3)
- # clojure-nl (3)
- # clojure-serbia (15)
- # clojure-spain (2)
- # clojure-uk (24)
- # clojurescript (54)
- # clojureverse-ops (3)
- # cursive (20)
- # datahike (4)
- # datalog (5)
- # datascript (8)
- # datomic (13)
- # emacs (2)
- # fulcro (1)
- # graalvm (2)
- # instaparse (1)
- # jobs (2)
- # luminus (1)
- # malli (7)
- # off-topic (28)
- # pathom (6)
- # pedestal (2)
- # re-frame (5)
- # reagent (9)
- # remote-jobs (4)
- # rewrite-clj (4)
- # ring (19)
- # shadow-cljs (2)
- # spacemacs (2)
- # sql (10)
- # tools-deps (6)
- # xtdb (12)
I’m very new to Crux: just been playing with it since @taylor.jeremydavid gave a talk to Clojure Provo about it — and it addresses several of the issues I had with Datomic (yay!). I have a question about processing query results: is there an idiomatic way to run a transform over query results as they are retrieved? In next.jdbc
I would use transduce
or reduce
over plan
to apply a transformation to each row and possibly accumulate results directly as the result set is retrieved from the database. What would be the equivalent in Crux?
Hey @U04V70XH6, welcome 👋 We expose an open-q
function which returns a Closeable
Iterator
of results - idiom is as follows:
(with-open [res (crux/open-q db '{:find ..., :where ...})]
(->> (iterator-seq res)
...))
I was hoping there was something that exposed a reducible context, but I guess I can wrap open-q
up in one (after all, that’s what clojure.java.jdbc
and next.jdbc
do under the hood).
Funnily enough we just opened a PR to add IReduceInit
to open-q
today 🙂 would that be sufficient? https://github.com/juxt/crux/pull/1477/files
I'd err on the side of us not merging that PR as it stands, FWIW - but certainly an idea for future API development
an external wrapper to open-q
(as opposed to wrapping the result of open-q
) would probably be a better shout, as @U04V70XH6 suggested
I mean, wrapping the result works, as the test suggests, but it might not guarantee everything that the next.jdbc
equivalents do - particularly, the ability to reduce
multiple times over the same plan
If you plan to do resource management via IReduceInit
, it should be in charge of opening the resource (as well as closing it) — not just close it at the end.
Since open-q
already does the opening of the resource, you can’t make its result directly reducible. You need a wrapper.
^ the Clojure-Provo talk I gave on Tuesday, referenced above, is now available at https://www.youtube.com/watch?v=wfaExQp9kes AMA :)