This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-08
Channels
- # announcements (6)
- # beginners (100)
- # calva (17)
- # cljs-dev (31)
- # cljsrn (2)
- # clojars (3)
- # clojure (137)
- # clojure-australia (1)
- # clojure-europe (41)
- # clojure-gamedev (3)
- # clojure-italy (1)
- # clojure-nl (3)
- # clojure-poland (16)
- # clojure-serbia (7)
- # clojure-taiwan (1)
- # clojure-uk (10)
- # clojurescript (10)
- # cursive (25)
- # data-oriented-programming (4)
- # datomic (26)
- # fulcro (39)
- # graalvm (6)
- # jobs (2)
- # jobs-discuss (2)
- # kaocha (19)
- # klipse (1)
- # leiningen (3)
- # lsp (18)
- # malli (21)
- # meander (26)
- # off-topic (29)
- # pathom (39)
- # polylith (3)
- # practicalli (2)
- # re-frame (11)
- # reitit (8)
- # rewrite-clj (7)
- # sci (11)
- # shadow-cljs (44)
- # sql (8)
- # tools-deps (32)
- # xtdb (3)
usingĀ `next.jdbc`,
how would it be possible to do batch-upsert (with column insertion), something like this: (this would work using java.jdbc
)
(jdbc/execute! db ["INSERT INTO T(col1, col2)
VALUES (?, ?)
ON DUPLICATE KEY UPDATE
col2=values(col2)"
[["c1" "c2"]
["c3" "c4"]]....more here] {:multi? true})
I've seen the sql.builder/for-insert-multi unit but this still means I need some strings work@aviv next.jdbc/execute-batch!
is what you're looking for I think. And you'd pass in that same string that you did for c.j.j. To build that string, HoneySQL is what you probably want (but ON DUPLICATE KEY
is MySQL I believe and not supported directly yet, but there is an open issue for it).
observing the prepare_test.clj I see this applied only when sending a prepared-statement, is there any way to avoid that?
Not at the moment, but you can easily create a PreparedStatement
with next.jdbc/prepare
so it's just a two-step process.
yep, thanks!
Now that execute-batch!
is in the next.jdbc
namespace, I may well implement it for sourceable/connectable as well, but I can't do it directly via the protocols because extending them at this point would be a breaking change I suspect. I may ask opinions about that in #clojure...
great, btw- awesome work!! docs, tests..etc
Thanks.