This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-06-18
Channels
- # aws-lambda (3)
- # beginners (57)
- # boot (3)
- # bristol-clojurians (1)
- # cider (38)
- # cljs-dev (23)
- # clojure (35)
- # clojure-italy (32)
- # clojure-nl (6)
- # clojure-spec (35)
- # clojure-uk (132)
- # clojurescript (34)
- # cursive (22)
- # data-science (1)
- # datomic (54)
- # devcards (1)
- # duct (5)
- # editors (7)
- # euroclojure (4)
- # fulcro (40)
- # graphql (1)
- # hoplon (6)
- # immutant (5)
- # jobs (1)
- # off-topic (22)
- # om (1)
- # planck (17)
- # portkey (1)
- # protorepl (12)
- # re-frame (97)
- # reagent (67)
- # reitit (16)
- # ring-swagger (1)
- # shadow-cljs (98)
- # spacemacs (8)
- # sql (20)
- # tools-deps (60)
So I'm running into an issue using YesQL and transactions. The overall issue is that I can't get the id of a newly created record back from within the transaction. Is this just a limitation of using transactions? I tried using RETURNING in the sql but the db called it a syntax error 😕
; This prints `nil` even though the client is created in the db
(defn create-client [client-info]
(jdbc/with-db-transaction [tx db-spec]
(let [client (-> client-info
hash-password
create-client<! {:connection tx})]
(println client)
client)))
; This creates a client row and prints it to the output
(defn create-client [client-info]
(let [client (-> client-info
hash-password
create-client<!)]
(println client)))
It seems like create-client<! isn't returning the row like it does outside of a transaction.
reading through the yesql generate.clj file now to figure out what might be going on
You might need parenthesis around create-client<! {:connection tx}
in your threading macro?
it could be using the pre-defined one instead of the override from the {:connection tx}
basically the create-client<!
was being called without the override connection map (due to missing parens), so that’d be my guess
Hint: you can macroexpand threading macros to see if it turns out to something that makes sense
Like here you would’ve probably noticed that the transaction example would’ve had {:connection tx}
calling the result of create-client<!
🙂