This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-04-17
Channels
- # aws (10)
- # beginners (64)
- # boot (3)
- # cider (20)
- # cljs-dev (32)
- # cljsrn (6)
- # clojure (126)
- # clojure-dusseldorf (3)
- # clojure-finland (1)
- # clojure-greece (1)
- # clojure-italy (7)
- # clojure-poland (3)
- # clojure-spec (46)
- # clojure-uk (100)
- # clojurescript (37)
- # cursive (11)
- # datomic (6)
- # defnpodcast (2)
- # emacs (1)
- # events (3)
- # figwheel (2)
- # fulcro (20)
- # immutant (2)
- # jobs (1)
- # jobs-discuss (9)
- # keechma (3)
- # lein-figwheel (1)
- # luminus (2)
- # lumo (3)
- # mount (2)
- # off-topic (19)
- # om (3)
- # om-next (2)
- # onyx (20)
- # other-languages (55)
- # parinfer (11)
- # pedestal (8)
- # portkey (3)
- # protorepl (3)
- # re-frame (22)
- # ring (9)
- # rum (1)
- # shadow-cljs (82)
- # spacemacs (28)
- # sql (15)
- # test-check (15)
- # testing (2)
- # tools-deps (102)
- # vim (26)
Hi. I'm using java.jdbc on my work.
I have two questions.
1) shoud I use :multi?
option, if I want to insert some records and using :return-keys
option?
A: (execute! db-spec ["insert into foo (x) values (?), (?)" "x" "y"] {:return-keys true})
vs
B: (execute! db-spec ["insert into foo (x) values (?)" ["x"] ["y"]] {:return-keys true :multi? true})
I know, these are differet results. My expectation is B's result, however I want to use A's query. Because Honey SQL don't support :multi?
option and A is fast.
2) Why :return-keys
should not work correctlly. foo
table has two columns, x
and y
, and I just needs x
column. So, I wrote the code like this.
(execute! db-spec ["insert into foo (x, y) values (?, ?)" "x" "y"] {:return-keys ["x"]})
But, I got a result as {:x "x", :y "y"}
. If I use prepare-statement
directly, it works. Is this a correct behavior?
execute! doesn't have a :return-keys
option, which is why it has no effect when you pass one in
have you tried using insert-rows!
? if I recall that just returns a collection of the inserted keys
https://github.com/clojure/java.jdbc/commit/5bdd1c03e049305bdb68925ec04e5c2eed2ec148
Now, execute!
support :return-keys
option, I think.
I was looking at an old check I had, which is why I said execute! doesn't take that option, if you are seeing it behave as if execute! doesn't have that option maybe you are using an old version where it doesn't
You mean, insert-multi!
? I don't want to use this. Because I'm using Honey SQL and HugSQL and so on.
from what I can see, the behavior of returning keys is largely determined by the underlying jdbc driver
execute! just passes the result-set to a function that generates a seq of maps from it
I added prepare-statement example https://gist.github.com/ayato-p/c8c2fbfc0efdd0dd56dc85fd694007fc#file-problem2-clj