Skip to content

Instantly share code, notes, and snippets.

@aviflax
Last active June 23, 2020 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aviflax/dfb111526667aaeb5baac4b79ccde0df to your computer and use it in GitHub Desktop.
Save aviflax/dfb111526667aaeb5baac4b79ccde0df to your computer and use it in GitHub Desktop.
Using Specter to modify deeply-nested values in a DaD DB. Start the REPL with `clj -A:repl:dad:specter`
; These aliased can/should be added to the same section in ~/.clojure/deps.edn
; They can then be “activated” by starting the REPL with: clj -A:repl:dad:specter
{:aliases
{:repl {:jvm-opts ["-XX:-OmitStackTraceInFastThrow"
"--illegal-access=deny"
"-Dclojure.server.repl={:port,0,:accept,clojure.core.server/repl}"]
:main-opts ["-e" "(.getLocalPort,(get-in,@#'clojure.core.server/servers,[\"repl\",:socket]))"
"-r"]}
;; *** LIBRARIES ***
:dad {:extra-deps {dad {:git/url "https://github.com/FundingCircle/dad"
:sha "865aa9711b3ff23940eaeb08cb12c41abf9fb508"}}}
:specter {:extra-deps {com.rpl/specter {:mvn/version "1.1.3"}}}}}
(require '[dad.db :as db])
(use 'com.rpl.specter)
(def db (db/read "db"))
(select [:technologies MAP-VALS "recommendations" ALL] db)
(->> db
(transform [:technologies MAP-VALS "recommendations" ALL]
#(-> (assoc % "proposed" {"by" (% "proposed-by")})
(dissoc "issued-by" "issued-on" "proposed-by")))
(db/overwrite))
@aviflax
Copy link
Author

aviflax commented Jun 22, 2020

Discover which technologies have recommendations that have been ratified:

(require '[dad.db :as db] '[medley.core :refer [filter-vals]])

(->> (db/read "db")
     (:technologies)
     (filter-vals (fn [tech] (some (fn [rec] (rec "ratified"))
                                   (get tech "recommendations"))))
     (keys))

I haven’t yet figured out how to do this with Specter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment