Created
March 1, 2021 17:14
-
-
Save stuarthalloway/9c0ab9f3e5f82e97ef78b8cbad9ce6b2 to your computer and use it in GitHub Desktop.
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
(defn pull-many | |
"Pull pattern from each entity in eids in a single eager query. | |
Returns a seqable of values sorted by: | |
sort-k if sort-k non nil | |
eids order if no sort-k specified | |
unsorted if sort-k is nil" | |
([db pattern eids] | |
(let [e->idx (into {} (map-indexed (fn [idx e] [e idx]) eids))] | |
(pull-many db pattern #(-> % :db/id e->idx) eids))) | |
([db pattern sort-k eids] | |
(let [result | |
(into | |
[] | |
(map first) | |
(d/q '[:find (pull ?e pattern) | |
:in $ pattern [?e ...]] | |
db pattern eids))] | |
(if sort-k | |
(sort-by sort-k result) | |
result)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment