Fork me on GitHub
#datomic
<
2017-07-01
>
dimovich08:07:19

how can I get the eids of newly added entities?

val_waeselynck09:07:07

@dimovich if said entities have a unique attribute, you can typically use the t of the corresponding datom

val_waeselynck09:07:51

It's hard to help you more without additional context

dimovich12:07:25

@val_waeselynck I'll look for the moment at tempids. Thanks for the info

dimovich12:07:56

btw, I have an {:id "someid :items [1 2 3 4]}

dimovich12:07:28

if I transact an entity with same id, the new items will be conjoined to the original :items

dimovich12:07:36

how can I replace them instead?

val_waeselynck13:07:19

@dimovich You need a transaction function for that. See for instance the one in Datofu https://github.com/vvvvalvalval/datofu#resetting-to-many-relationships

dimovich15:07:51

isn't there a built-in solution?

val_waeselynck15:07:04

No, but when you think about it, there isnt either for sql databases.

dimovich18:07:21

btw, whenever I make a transaction, if I do a query afterwards (against the new db value) I don't get the new entities

dimovich18:07:33

I get them if I repeat the query

dimovich18:07:42

maybe it's related to caching...

dimovich18:07:51

or memoization

souenzzo18:07:10

@dimovich db is immutable. Once you get a db (let [db (d/db conn)] ), it will NEVER change. If you want a new db, you can make a new (d/db conn), or in case of a transaction, a transaction returns a future, that you can deref and get the db-after and db-before.

souenzzo18:07:36

(defn handler
  [req]
  (let [db (get req :db)
        conn (get req :conn)
        params (get req :params)
        tx-data (do-stuff db params)
        tx (d/transact conn tx-data)
        db-after (get @tx :db-after)]
    (my-query-stuff db-after params)))

souenzzo18:07:11

About "to-many" problem, [{:id "foo" :items [1 2]}] is a sugar syntax to [[:db/add [:id "foo"] :items 1][:db/add [:id "foo"] :items 2]]. If you want to remove a thing from a many, you should explicit do it. In my app, there is a generic (update-to-many db x), that walk across all maps, identify it, check to many atributes, compare with database and generate the retracts...