Skip to content

Instantly share code, notes, and snippets.

@tolitius
Last active December 29, 2016 16:06
Show Gist options
  • Select an option

  • Save tolitius/75ef1663ae462b68ee2f070ee83cbe01 to your computer and use it in GitHub Desktop.

Select an option

Save tolitius/75ef1663ae462b68ee2f070ee83cbe01 to your computer and use it in GitHub Desktop.
pipelining

data store tools

These tools in reality would probably live behind a protocol for a polymorphic runtime dispatch (i.e. so they can be added to varous store types)

(defn select [conn query]
  (println "reading from" conn "query:" query)
  [1 2 3])

(defn insert [conn query]
  (println "writing to" conn "data:" query))

"business" functions

(defn inc-all [xs]
  (map inc xs))

(defn sum [xs]
  (reduce + xs))

REPL time

single db call

  • read from a datastore
  • calculate something
  • calculate more
(-> :data-store                                 ;; in reality this would be a real connection object
    (select {:where {:status "ready"}})
    inc-all
    sum)

results:

reading from :data-store query: {:where {:status ready}}
9

multiple db calls

  • read from a datastore
  • calculate something
  • calculate more
  • write it to a data store
(let [db :data-store]                          ;; in reality this would be a real connection object
  (->> (select db {:where {:status "ready"}})
       inc-all
       sum
       (insert db)))

results:

reading from :data-store query: {:where {:status ready}}
writing to :data-store data: 9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment