This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-07-05
Channels
- # aws (12)
- # babashka (30)
- # beginners (294)
- # calva (98)
- # clj-on-windows (3)
- # clojure (48)
- # clojure-europe (31)
- # clojure-italy (8)
- # clojure-nl (2)
- # clojure-uk (11)
- # clojurescript (58)
- # conjure (1)
- # events (1)
- # fulcro (35)
- # graalvm-mobile (2)
- # jobs (8)
- # lsp (11)
- # malli (25)
- # off-topic (33)
- # pathom (24)
- # pedestal (1)
- # polylith (15)
- # re-frame (7)
- # reitit (10)
- # releases (8)
- # remote-jobs (2)
- # sci (3)
- # shadow-cljs (79)
- # spacemacs (10)
- # sql (17)
- # tools-deps (17)
- # vim (4)
- # xtdb (11)
Can I use ‘var’ here by any chance? The query I want to use looks like this.
INSERT INTO test (id)
VALUES (@var := 1)
ON DUPLICATE KEY
UPDATE id=(@var := id + 1);
this feels like a sql question - if the insert helper doesn't do enough for you, just use execute!
I tried to solve it with insert helper, but in the end, I used ‘execute!’ as you said.
Good Morning Clojurians, I am trying to understand how to use next jdbc transactions. In the example code:
(jdbc/with-transaction [tx my-datasource]
(jdbc/execute! tx ...)
(jdbc/execute! tx ...)) ; will commit, unless exception thrown
I getting stuck on the my-datasorce
argument. I tried to look through documentation and could not find what to use as an argument. Anyone has an example of how to use transaction?my-datasource
should either be a connection or a datasource (or your connection pool). If you want a datasource then you should call (jdbc/get-datasource db-spec)
. Where db-spec
is a hash-map with entries listed https://github.com/seancorfield/next-jdbc/blob/develop/doc/all-the-options.md#datasources-and-connections.
db-spec
is the config that describes how to connect to the database, details like username, password, host and so on.
@UMPJRJU9E, ok than what is tx
?
I thought the tx
was the datasource since it is required by the jdbc/execute!
tx is just a binding, like your let bindings, the with-transaction
is a macro that will create a transaction object from the supplied datasource/connection and bind it to tx
. And this tx
can be passed to the statements which you want to run inside that transaction.
Found some examples https://grep.app/search?q=with-transaction%20%5Btx
@UMPJRJU9E, ok, wow, never know about the http://grep.app. This is awesome!!!
@U012GN57FJ9 with-transaction
is like with-open
in Clojure: it introduces a new local binding with either a new connection drawn from the specified datasource, or by starting a transaction on the specified connection (which is why it is recommended to use a datasource there).
Like with-open
, it "cleans up" the transaction at the end and closes the connection if it opened one.
I'll try to make that clearer in the docs.
@U04V70XH6, thank you. If you could add a simple example of what to give to transaction it would be perfect. One example can be worth 2000 words.