AdStage / pluck-api

An extensible wrapper around Datomic's pull API.
MIT License
30 stars 0 forks source link

Support for pluck-many. #7

Closed currentoor closed 7 years ago

currentoor commented 7 years ago

There should be an analog to datomic.api/pluck-many. The pluck handlers for specific keys in this case should return collections, to avoid n+1 queries.

(defmethod -pluck-many :dashboard/org-time [k {db :db} dashboards]
  (->> (d/q '[:find  ?d ?created-at
              :in    $ [?d ...]
              :where [?d :dashboard/organization _ ?org-tx _] 
                     [?org-tx :db/txInstant ?created-at]]
            db
            (map :db/id dashboards))
       (into [])))

(pluck-many {:db db} [:db/id :dashboard/title :dashboard/org-time] [d1 d2])
;=> [{:db/id d1 :dashboard/title "FooBar" :dashboard/org-time #inst "2016-08-20T22:10:26.652-00:00"}
;=>  {:db/id d2 :dashboard/title "BarFoo" :dashboard/org-time #inst "2016-08-21T22:10:26.652-00:00"}]