Skip to content

Instantly share code, notes, and snippets.

@pyrtsa
Last active June 20, 2019 21:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pyrtsa/84b1c86764425a7f3def to your computer and use it in GitHub Desktop.
Save pyrtsa/84b1c86764425a7f3def to your computer and use it in GitHub Desktop.
Getting Datomic query results as a sequence of maps.
(defn q-maps
[query & args]
{:pre [(map? query)]}
(let [ks (map #(-> % name (subs 1) keyword) (:find query))
rs (apply datomic.api/q query args)]
(map (partial zipmap ks) rs)))
(q-maps {:find '[?id ?val]
:where '[[?e :id ?id] [?e :val ?val]]}
db)
;;=> ({:val 150, :id "d"} {:val 122, :id "a"} {:val 123, :id "b"})
(q-maps {:find '[?i ?v] :where '[[?e :id ?i] [?e :val ?v]]} @d)
;;=> ({:v 150, :i "d"} {:v 122, :i "a"} {:v 123, :i "b"})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment