Love the addition of (find-all-states)
and (running-states)
. I'm going to start using the latter inside use-fixtures
so that I can return the app state back to what it was before tests were run.
Is it possible to have binding
style semantics in mount?
If I have this:
(defstate db
:start (start-db config)
:stop (stop-db db))
(defn insert-into-db
[table row]
(jdbc/insert! db table row))
Then I want to wrap my database calls in a transaction:
(jdbc/with-db-transaction [conn db]
(binding [db conn]
(insert-into-db :things {:id 1 :name "first thing"})
(insert-into-db :things {:id 2 :name "second thing"})))
How do I do this sort of thing with mount? Or is there a better approach to this sort of problem?@mnewt you could use a dynamic var, e.g:
(defstate ^:dynamic *conn*
:start (connect!)
:stop (disconnect! *conn*))
then you can do
(binding [*conn* t-conn]
…)
this is how I end up doing it in the conman lib for luminus https://github.com/luminus-framework/conman/blob/master/src/conman/core.clj#L88
Ah, that’s simple! Didn’t realize defstate
would work just like def
. Thanks @yogthos!
np