«

Index APIs

Most Datomic programs will not access the indexes directly, instead taking advantage of Datomic's declarative Datalog query engine.

However, raw index access is available for integrations. For example, you might use the indexes to make Datomic data available to a map/reduce framework spanning multiple data sources of different types.

Datomic indexes are covering indexes. This means the index actually contains the datoms, rather than just a pointer to them. When you (or a Datomic query) iterates an index, it gets the datoms themselves, without any additional lookup.

Datoms API

Peer API | Client API

The Datoms API lets you specify a Datomic index, plus a vector of values in the same order as the index. The example excerpted below searches the :avet index for datoms whose a component is :inv/sku

;; Peer API
(->> (d/datoms db :avet :inv/sku)
     (take 3)
     (map :v))

;; Client API
(->> (d/datoms db
               {:index :avet
                :components [:inv/sku]})
     (take 3)
     (map :v))
=> ("SKU-0" "SKU-1" "SKU-10")

Index-range API

Peer API | Client API

The index-range API lets you specify an attribute, and returns all datoms sorted by that attribute, optionally limited by start and end values. The example excerpted below returns all the SKUs between "SKU-42" inclusive and "SKU-44" exclusive.

;; Peer API
(->> (d/index-range db :inv/sku "SKU-42" "SKU-44")
     (map :v))

;; Client API
(->> (d/index-range
      db
      {:attrid :inv/sku
       :start "SKU-42"
       :end "SKU-44"})
     (map :v))
=> ("SKU-42" "SKU-43")