Fork me on GitHub
#xtdb
<
2019-10-29
>
plexus09:10:15

perhaps this will be useful to some

(defn touch [component-keys db entity]
  (let [touch (partial touch component-keys db)]
    (into
     {}
     (map (fn [[k v]]
            [k
             (if (some #{k} component-keys)
               (if (vector? v)
                 (mapv (comp touch (partial c/entity db)) v)
                 (touch (crux/entity db v)))
               v)]))
     entity)))

(let [db (crux/db crux-node)]
  (->> #uuid "ce20cc92-a55a-4bf7-9282-4df9f4cbb9e2"
       (crux/entity db)
       (touch #{:procflow.procedure/steps} db)))
;; => {:procflow.procedure/steps
;;     [{:procflow.step/type :text,
;;       :crux.db/id #uuid "f45d3c5d-a911-475f-8271-bd8078d131ec"}],
;;     :crux.db/id #uuid "ce20cc92-a55a-4bf7-9282-4df9f4cbb9e2"}

plexus09:10:35

given an entity and a set of keys that are references to other entities, recursively look up the referred entities. Somewhat like what datomic's entity does with :isComponent, except that it's not lazy

plexus09:10:03

argument order is chosen so it's easy to partially apply the set of keys

jonpither20:10:04

Hi @plexus - welcome to the Crux channel! Thanks for this code & pattern - we will consider adding to the docs (with the relevant credit).

4