On Wednesday, January 7, 2015 at 2:49:50 PM UTC-6, Sean Corfield wrote: > > On Jan 7, 2015, at 10:21 AM, Allen Rohner <aro...@gmail.com <javascript:>> > wrote: > > As a design rule, I prefer making I/O fns (things that hit the DB or a > REST API), 'dumb', and perform all logic/processing in fns that just > receive plain data, and return plain data. > > In my current project, I'm using component + datomic, so I'll talk about that here.
> I’m curious: do you have wrapper functions for the DB reads/writes (i.e., > a domain layer that just wraps the calls to your persistence library as > well as managing the connections etc)? > > Yes. Finding a user looks like (defn get-user-by-login [db login] (d/q '[:find (pull ?u [*]) :in $ ?login :where [?u :user/login ?login]] db login)) I'm passing the datomic DB value into the find function. Currently we primarily run Clojure as the embedded "Model" in a legacy MVC > app so we can’t really use Stuart’s Component (at least, I don’t think we > can, because we have a lot of entry points into the Clojure code) but we > would like to figure out a cleaner way to separate DB access from our > business logic on a per request basis... > > The important part of component isn't using the actual library, it's the philosophy. The most important thing is the signatures on your fns. You "just" need to change all of your code to take the DB connection as an argument, rather than doing something like: (defn get-user-by-login [login] (d/q '[:find...] db login)) The only difference from the first example is that the DB is no longer an argument, so now it's implicit global state. Fixing that is 90% of the benefit of component, the rest of component is designed to make starting the system simpler. Component may or may not be a good fit for you, but you can certainly get most of the benefit on your own. Thanks, Allen > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.