Created
January 9, 2017 14:54
-
-
Save pesterhazy/5b428176f84b06d1d68bdc97ea7823f8 to your computer and use it in GitHub Desktop.
Datomic REPL helpers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 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