Last active
June 20, 2019 21:00
-
-
Save pyrtsa/84b1c86764425a7f3def to your computer and use it in GitHub Desktop.
Getting Datomic query results as a sequence of maps.
This file contains 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
(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