This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-02-01
Channels
- # aleph (71)
- # aws (1)
- # bangalore-clj (4)
- # beginners (36)
- # boot (153)
- # cider (23)
- # clara (9)
- # cljs-dev (67)
- # cljsjs (2)
- # cljsrn (22)
- # clojure (348)
- # clojure-argentina (4)
- # clojure-austin (12)
- # clojure-berlin (9)
- # clojure-dusseldorf (6)
- # clojure-france (4)
- # clojure-italy (4)
- # clojure-russia (358)
- # clojure-spain (2)
- # clojure-spec (28)
- # clojure-uk (109)
- # clojurescript (130)
- # core-typed (1)
- # cursive (35)
- # datascript (6)
- # datomic (18)
- # emacs (12)
- # hoplon (4)
- # klipse (64)
- # lein-figwheel (13)
- # leiningen (3)
- # luminus (4)
- # lumo (51)
- # mount (22)
- # off-topic (83)
- # om (22)
- # om-next (8)
- # onyx (3)
- # pedestal (8)
- # perun (6)
- # portland-or (2)
- # re-frame (50)
- # ring (8)
- # ring-swagger (5)
- # untangled (10)
- # yada (9)
just found mount 🎉 been looking for ways to manage state without passing an extra parameter to every function (so Component’s out) Question: if I want to use Mount to e.g. connect to two databases at once, would I use Yurt for that? Say I want to run a database upgrade, reading from one database and writing to another.
(defstate from-db :start (connect {...}) :stop ...)
(defstate to-db :start (connect {...}) :stop ...)
(ns db-access
(:require [my-ns :refer [db]]))
(defn people
(query db "select * from people"))
(defn people-add [peeps]
(bulk-insert db "insert into people" peeps))
I have a single db access namespace that calls some db library to do the actual interaction
yea, unless I am missing something, you are using a single state
(i.e. a single connection, a single resource) that you use to perform different actions: select, insert, update...
ah.. hold on. you are using db access for more than one database in the same runtime?
yes, here is what it would look like with naive code:
(ns db-access)
(defn people [db]
(query db "select * from people"))
(defn people-add [db peeps]
(bulk-insert db "insert into people" peeps))
(ns top
(:require [db-access :refer [people people-add]]))
(def db-from “something-something”)
(def db-to “something-else-entirely”)
(defn transfer [db-from db-to])
(people-add db-to (people db-from))
seems like I’d have to spin up two Yurts and make transfer
call into the first one to get the people and then call into the second one to insert the people
I would recommend using the args:
(defn people [db]
(query db "select * from people"))
since no matter how you manage your state:
(defn people []
(query db "select * from people"))
will always use the same db (the same connection / resource). i.e. not really mount or really mount or component specific
there is one gotcha to this, which is, in testing, or for different use case, you can use mount/start-with
: https://www.dotkam.com/2016/01/17/swapping-alternate-implementations-with-mount/ok thanks @tolitius. I clearly misunderstand Mount and need to go study more. I thought the whole point was to eliminate the configuration parameter (`db` in this case) from my argument lists, allowing me to refer to the configuration parameter(s) (from within my function bodies) as if they were in the enclosing environment