Hi,

An email to the Datomic mailing list piqued my interest, so I have added a
new funtion to the Tupelo Datomic library which allows the user to easily
(& efficiently) retrieve all Entity IDs (EIDs) from a given partition
(specified as a keyword).

For example, suppose in our James Bond Unit Test
<https://github.com/cloojure/tupelo/blob/master/test/tst/tupelo/datomic_bond.clj>
we
wish to add Honey Rider to the partition :people.  Then we could use code
like this:

ns tst.tupelo.datomic-bond
  (:require [tupelo.datomic   :as td] ...

  ; Create a partition named :people (we could namespace it like
:db.part/people if we wished)
  (td/transact *conn*
    (td/new-partition :people ))

  ; Create Honey Rider and add her to the :people partition
  (let [tx-result   @(td/transact *conn*
                        (td/new-entity :people ; <- partition is first arg
(optional) to td/new-entity
                          { :person/name "Honey Rider" :location
"Caribbean" :weapon/type #{:weapon/knife} } ))
        [honey-eid]  (td/eids tx-result)  ; retrieve Honey Rider's EID from
the seq (destructuring)
  ]
    (is (s/validate ts/Eid honey-eid))  ; verify the expected type
    (is (= :people                      ; verify the partition name for
Honey's EID
           (td/partition-name (live-db) honey-eid)))

Suppose we wanted a listing of all EIDs in the :people partition.  The
simple way is to use the new function partition-eids as follows:

    ; Show that only Honey is in the people partition
    (let [people-eids           (td/partition-eids (live-db) :people)
          people-entity-maps    (map #(td/entity-map (live-db) %)
people-eids) ]
      (is (= people-entity-maps [
               {:person/name "Honey Rider", :weapon/type #{:weapon/knife},
:location "Caribbean"} ] )))

So Honey is, indeed, the only person in the newly created :people partition,
and we have used the handy function entity-map to convert her EID into a
normal Clojure map for further processing.

Enjoy!
Alan

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to