Fork me on GitHub
#clojure-norway
<
2022-12-14
>
slipset09:12:34

God morgen!

slipset09:12:54

Og godt å see litt konkurranse på jobbmarkedet 🙂

⚔️ 2
slipset16:12:14

Har jeg liksom akkurat løst det vi trengte for 1.5fase commit over mongo og pg i ca 10 linjer Clojure?

slipset16:12:00

(defn call-in-transaction
  "A very rudimentary fn to ensure that either we persist to both databases or we don't persist to any of them. Only works on `org-db` and `org-ds` for now."
  [ctx f]
  (postgres/with-reused-transaction [_ (:org-ds ctx)]
    (m/with-transaction (:org-db ctx)
      (f)
      (postgres/prepare-transaction! (:org-ds ctx) (gensym)))))
og
(defn prepare-transaction! [ds id]
  (jdbc/execute! ds [(str  "PREPARE TRANSACTION '" id "'")]))

slipset19:12:03

Det var faktisk enda enklere:

(defn call-in-transaction
  "A very rudimentary fn to ensure that either we persist to both databases or we don't persist to any of them. Only works on `org-db` and `org-ds` for now.
  `f` is a fn that accepts a `ctx` as a parameter"
  [{:keys [org-db org-ds] :as ctx} f]
  (postgres/with-reused-transaction [tx org-ds]
    (m/with-transaction org-db
      (f (assoc ctx :org-ds tx)))))