Skip to content

Instantly share code, notes, and snippets.

@favila
Created February 8, 2017 18:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save favila/6366516f2bef6b77b07f7349d4ff009e to your computer and use it in GitHub Desktop.
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
(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