Fork me on GitHub
#datomic
<
2015-12-03
>
genRaiy20:12:29

must be the n00best question ever … but here goes … how do I get the data back after an add on the DB? The only twist is that there are components in the record being saved so I cannot tell which id is the resolved ID for the ‘outer’ object

genRaiy20:12:01

data looks like this

genRaiy20:12:05

(def cart {:cart/name       "Bunky cart"
           :cart/id (java.util.UUID/randomUUID)
           :cart/sku-counts [{:sku-count/sku   12345
                              :sku-count/count 3
                              }
                             {:sku-count/sku   54321
                              :sku-count/count 4
                              }]})
=> #'shopping-cart-demo.datomic/cart
(save-new-cart conn cart)

genRaiy20:12:25

result looks like this

genRaiy20:12:29

{:db-before datomic.db.Db,
 @db33bdaf :db-after,
 datomic.db.Db @f673e86,
 :tx-data [#datom[13194139534347 50 #inst"2015-12-03T20:15:35.122-00:00" 13194139534347 true]
           #datom[17592186045452 64 "Bunky cart" 13194139534347 true]
           #datom[17592186045452 63 #uuid"a192e41c-461a-44dc-a662-57ae652816d6" 13194139534347 true]
           #datom[17592186045452 65 17592186045453 13194139534347 true]
           #datom[17592186045453 66 12345 13194139534347 true]
           #datom[17592186045453 67 3 13194139534347 true]
           #datom[17592186045452 65 17592186045454 13194139534347 true]
           #datom[17592186045454 66 54321 13194139534347 true]
           #datom[17592186045454 67 4 13194139534347 true]],
 :tempids {-9223354444667731342 17592186045454,
           -9223354444667731343 17592186045453,
           -9223350046623220336 17592186045452}}

genRaiy20:12:35

so it all worked

genRaiy20:12:59

question now is which ID do i plug into the following query

genRaiy20:12:21

(d/pull (:db-after tx) '[*] cart-id)

genRaiy20:12:07

I happen to know (from querying the DB manually) that the ID is the last one in the map

Lambda/Sierra20:12:39

@raymcdermott: You have to hold on to something to reference the entity. It could be a unique identity, such as a UUID, to use in a lookup ref. Or keep the tempid and use resolve-tempid to get the real Entity ID.

genRaiy20:12:01

ah nice ok I will use the resolve-tempid …. thanks

genRaiy20:12:23

@stuartsierra: boom! worked a treat, thanks

Lambda/Sierra21:12:07

You're welcome

genRaiy22:12:02

question about component entities …. is there anyway to remove them all at once rather than one by one (I want to keep the entity they’re a part of as more elements in the component entries could be added later)

genRaiy22:12:39

it’s not a huge hassle to enumerate over them … just wondered if there was a shortcut