Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(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
(map first)
(d/q '[:find (pull ?e pattern)
:in $ pattern [?e ...]]
db pattern eids))]
(if sort-k
(sort-by sort-k result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment