Getting the id of an inserted entity in datomic?

前端 未结 4 1854
臣服心动
臣服心动 2021-02-19 20:43

After I run a transaction in datomic to insert a value, how I can use the return value of the transaction to get the ids of any entities that were created?

Here is a sam

4条回答
  •  执笔经年
    2021-02-19 21:15

    The Tupelo Datomic library has a function (td/eids tx-result) to easily extract the EIDs created in a transaction. For example:

      ; 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)
      ]
    

提交回复
热议问题