This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-07-05
Channels
- # announcements (5)
- # babashka (2)
- # beginners (47)
- # calva (3)
- # cider (42)
- # clerk (5)
- # clj-commons (21)
- # clojure (145)
- # clojure-austin (25)
- # clojure-europe (14)
- # clojure-norway (9)
- # clojure-spec (7)
- # clojurescript (21)
- # datomic (4)
- # dev-tooling (4)
- # docker (5)
- # gratitude (5)
- # honeysql (6)
- # hyperfiddle (45)
- # jobs (1)
- # juxt (2)
- # malli (25)
- # meander (1)
- # mount (3)
- # other-languages (7)
- # pathom (7)
- # pedestal (1)
- # reagent (5)
- # reitit (20)
- # releases (2)
- # remote-jobs (1)
- # shadow-cljs (77)
- # squint (8)
- # tools-deps (34)
X-posting https://clojurians.slack.com/archives/C03S1KBA2/p1688475389326749 question here as it’s related to mount:
I don't understand what you mean by "redef the new read-only datasource state with the older state". Judging from the error you are using with-redefs
wrong, you should drop the "constantly" call. Some of this might be helpful: https://github.com/tolitius/mount/#swapping-alternate-implementations
I have looked into that, but I can’t figure out how to swap my state with alternate implementation. I have these macros defined on the 2 datasources:
(defstate datasource
:start (do (log/info "Starting DB connection pool")
(hikari/make-datasource (:db config/config)))
:stop (do (hikari/close-datasource datasource)
(log/info "Closed DB connection pool")))
(defstate read-only-datasource
:start (do (log/info "Starting read-only DB connection pool")
(hikari/make-datasource (merge (:db config/config)
(:read-only-db config/config))))
:stop (do (hikari/close-datasource datasource)
(log/info "Closed read-only DB connection pool")))
(defmacro with-transaction [[transaction] & body]
`(jdbc/with-db-transaction
[~transaction {:datasource datasource}]
~@body))
(defmacro with-read-only-transaction [[transaction] & body]
`(jdbc/with-db-transaction
[~transaction {:datasource read-only-datasource}]
~@body))
and I want to either replace the state within with-read-only-transaction
to use the normal datasource in tests