This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-02-26
Channels
- # announcements (1)
- # babashka (6)
- # beginners (12)
- # biff (39)
- # calva (4)
- # cider (5)
- # clj-commons (1)
- # clj-yaml (9)
- # clojure (42)
- # clojure-conj (1)
- # clojure-europe (8)
- # clojurescript-ios (1)
- # clr (1)
- # conjure (7)
- # data-science (1)
- # datalevin (9)
- # emacs (3)
- # helix (1)
- # honeysql (11)
- # hyperfiddle (60)
- # introduce-yourself (1)
- # lsp (26)
- # music (1)
- # off-topic (1)
- # pathom (2)
- # polylith (3)
- # releases (1)
- # sci (1)
- # scittle (21)
- # shadow-cljs (57)
- # spacemacs (3)
- # xtdb (38)
hi y’all 🙂 I want to use jdbc/execute-batch! for updating several records with batch. how can I use it with honeysql? honey.sql/format
function is working only for 1 record and not batch. tnx!
A somewhat similar previous discussion: https://clojurians.slack.com/archives/C66EM8D5H/p1625797454111000
That doesn't exactly answer your question, but if you need that to insert multiple items then there's insert-multi!
.
Unfortunately it’s not the use-case…
I need to update values in batch, so I’m searching something with this template:
(jdbc/execute-batch! ds
"UPDATE agent_event SET seen = TRUE WHERE (agent_id = ?) AND (event_id IN (?))"
[["id1" "eid1"] ["id2" "eid2"] ["id3 "eid3"]])
Only that I want to use honey.sql to build the sql statement instead of writing the statement itselftrying to figure out what will work on this case
Not sure whether it's the best approach but you can create a regular sqlmap where all the positional parameters are represented by [:raw "?"]
.
(honey.sql/format {:update :agent-event
:set {:seen [:inline true]}
:where [:and
[:= :agent-id [:raw "?"]]
[:in :event-id [[:raw "?"]]]]})
=> ["UPDATE agent_event SET seen = TRUE WHERE (agent_id = ?) AND (event_id IN (?))"]
Thanks 🙏 I had [:raw "?"]
missing 🙂
Perhaps slightly less ugly:
user=> (honey.sql/format {:update :agent-event
#_=> :set {:seen [:inline true]}
#_=> :where [:and
#_=> [:= :agent-id :'?]
#_=> [:in :event-id [:nest :'?]]]})
["UPDATE agent_event SET seen = TRUE WHERE (agent_id = ?) AND (event_id IN (?))"]
:'
allows for "literal" symbols