Open Time Store™
Copyright © JUXT LTD 2018-2019


Here we document patterns and helpful functions that have been suggested by users. A broad understanding of these patterns will be useful to guide iterations on the next generation of API layers for Crux. Some of these patterns may be appropriate candidates for evolving into easily consumable decorators.


PRs are welcome, see Contributing for guidelines. If you would prefer not to sign up to our CLA just point us towards your GitHub gist and we can link to it.

(defn entity-update
  [entity-id new-attrs valid-time]
  (let [entity-prev-value (crux/entity (crux/db node) entity-id)]
    (crux/submit-tx node
        (merge entity-prev-value new-attrs)

; by @spacegangster

Implicit Node

(defn q
  (crux/q (crux/db node) query))

(defn entity
  (crux/entity (crux/db node) entity-id))

; by @spacegangster


(defn lookup-vector
 [db eid]
 (if (vector? eid)
   (let [[index value] eid]
         (crux.api/q db
                     {:find ['?e]
                      :where [['?e index value]]}))))
   (crux.api/entity db eid)))

; by @SevereOverfl0w
(defn entity-at
  [entity-id valid-time]
  (crux/entity (crux/db node valid-time) entity-id))

(defn entity-with-adjacent
  [entity-id keys-to-pull]
  (let [db (crux/db node)
        (fn [ids]
          (cond-> (map #(crux/entity db %) ids)
            (set? ids) set
            (vector? ids) vec))]
      (fn [e adj-k]
        (let [v (get e adj-k)]
          (assoc e adj-k
                   (keyword? v) (crux/entity db v)
                   (or (set? v)
                       (vector? v)) (ids->entities v)
                   :else v))))
      (crux/entity db entity-id)

; by @spacegangster

Transaction Ops

; Use spec to validate your operations prior to submission

   (clojure.spec.alpha/or :put :crux.tx/put-op
                          :delete :crux.tx/delete-op
                          :cas :crux.tx/cas-op
                          :evict :crux.tx/evict-op)
    {:crux.db/id #uuid "6f0232d0-f3f9-4020-a75f-17b067f41203"
     :name "John Wayne"
     :username "jwa"}
    {:crux.db/id #uuid "6f0232d0-f3f9-4020-a75f-17b067f41203"
     :name "John Wayne"
     :username "jwa"
     :new-field 2}])

; by @SevereOverfl0w