Skip to content

Instantly share code, notes, and snippets.

@pesterhazy
Created January 9, 2017 14:54
Show Gist options
  • Save pesterhazy/5b428176f84b06d1d68bdc97ea7823f8 to your computer and use it in GitHub Desktop.
Save pesterhazy/5b428176f84b06d1d68bdc97ea7823f8 to your computer and use it in GitHub Desktop.
Datomic REPL helpers
;; Makes it easier to work from the REPL
;;
;; Don't use these from production functions
(defonce !c (atom nil))
(defn rdc []
(let [c @!c]
(assert c "Database not connected")
c))
(defn rdb
"Repl Datomic Db"
[] (->> (rdc) d/db))
(defn rdq
"Repl Datomic Query"
[x & more]
(apply d/q x (rdb) more))
(defn rdp
"Repl Datomic Pretty-Print"
[v]
(->> v (into {}) pprint))
(defn rde
"Repl Datomic Entity"
[& args]
(when-let [e (apply d/entity (rdb) args)]
(d/touch e)))
(defn rdi
"Repl Datomic entity Id"
[& args] (apply d/entid (rdb) args))
(defn rdu
"Repl Datomic pull"
([entid]
(d/pull (rdb) '[*] entid))
([pattern entid]
(d/pull (rdb) pattern entid)))
(defn rdoit!
([] (rdoit! *1))
([txs]
@(d/transact-async (rdc) txs)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment