This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-10-29
Channels
- # announcements (2)
- # babashka (2)
- # beginners (76)
- # boot (6)
- # calva (7)
- # cider (12)
- # clara (4)
- # clj-kondo (11)
- # cljdoc (9)
- # cljs-dev (21)
- # cljsrn (7)
- # clojure (72)
- # clojure-dev (158)
- # clojure-europe (2)
- # clojure-italy (3)
- # clojure-losangeles (3)
- # clojure-nl (5)
- # clojure-spec (29)
- # clojure-uk (93)
- # clojurescript (40)
- # cursive (7)
- # data-science (1)
- # datomic (28)
- # defnpodcast (5)
- # duct (5)
- # emacs (7)
- # events (2)
- # figwheel-main (5)
- # fulcro (55)
- # graalvm (2)
- # instaparse (1)
- # jobs (5)
- # juxt (1)
- # luminus (3)
- # nyc (2)
- # pathom (3)
- # planck (25)
- # re-frame (2)
- # reagent (4)
- # reitit (23)
- # shadow-cljs (381)
- # spacemacs (6)
- # sql (19)
- # tools-deps (7)
- # xtdb (4)
;; this works
(defn slack-allowed []
(let [ds (jdbc/get-datasource datasource)]
(with-open [con (jdbc/get-connection ds)]
(conj '()
(jdbc/execute! con ["SELECT ?" 7])
(jdbc/execute! con ["SELECT ?" 8])))))
;; this doesn't - execute() is called on closed connection
(defn slack-denied []
(let [ds (jdbc/get-datasource datasource)]
(with-open [con (jdbc/get-connection ds)]
(map (fn [num] (jdbc/execute! con ["SELECT ?" num])) (range 7 9)))))
so the function is evaluated after the with-open has returned. (probably when the result is printed at the repl)
@dharrigan thanks .. that's it - and the repl trying to print forces the execution after the con
is closed
I'm returning 1mil records from a next.jdbc/execute!
call. Is there a way to avoid realizing the entire resultset into memory? I looked into next.jdbc/plan
but couldn't discern if that would help in this situation.
@joe.lane plan
is designed for that situation, yes.
Because it lets you process (`reduce`) the entire result set without realizing it into Clojure data.
Fantastic @seancorfield! My scenario is put all results on a channel one at a time
. Does it make sense to just a/put!
inside a reduce
call?
Yeah, although bear in mind: a) you'll need to realize each row into Clojure data to put them on a channel and b) you'll still end up with all that data realized into memory depending on how much is buffered and how fast it gets processed out of the channel on the other end.
with put!, only the global backpressure on put! itself will keep all results from being in memory
(and I suspect folks may advise against coupling blocking I/O with core.async... and there it is)
if you use >!! instead, the realization will have backpressure based on the channel buffer and consumption this should be outside a go block NB