Created
February 8, 2017 18:19
-
-
Save favila/6366516f2bef6b77b07f7349d4ff009e to your computer and use it in GitHub Desktop.
entity-pull: a datomic.api/pull that returns values the way datomic.api/entity would, with sets and ident keywords
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
(require '[datomic.api :as d]) | |
(defn entity-pull | |
"Like pull, but returns values consistent with d/entity, i.e., | |
entities with :db/ident are represented as keywords and sets are | |
used instead of vectors." | |
[db pat eid] | |
(->> (d/pull db pat eid) | |
(clojure.walk/prewalk | |
(fn [x] | |
(cond | |
(and (not (map-entry? x)) (vector? x)) (set x) | |
(and (map? x) (:db/ident x)) (:db/ident x) | |
(and (map? x) (:db/id x)) (or | |
(:db/ident (d/entity db (:db/id x))) | |
x) | |
:else x))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment