Fork me on GitHub
#datomic
<
2015-06-15
>
lboliveira13:06:23

Hello, I want to use an entity returned by d/touch as if it were a map, assoc'ing new keys, etc. How should I do that? Example:

(let [entity (->> (d/q '[:find ?e .
                              :where [?e :db/ident ]]
                         (d/db conn))
                    (d/entity (d/db conn))
                    d/touch)]
    (assoc entity :answer 42) )
The following code is throwing a CompilerException java.lang.AbstractMethodError.

hmadelaine13:06:31

(let [entity (->> (d/q '[:find ?e .
                     :where [?e :db/ident]]
                   (d/db conn))
              (d/entity (d/db conn))
              d/touch
              (into {}))]
  (assoc entity :answer 42))

lboliveira13:06:44

@hmadelaine: It worked. 😃 Thank you!

hmadelaine13:06:13

@lboliveira: not sure this is the best solution

lboliveira13:06:54

@hmadelaine: it is small at least. simple_smile

robert-stuttaford14:06:55

@lboliveira @hmadelaine: you should use the pull api which returns normal clj data

robert-stuttaford14:06:23

(d/pull db ‘[*] your-id-or-lookup-ref-or-entity-reference-here) http://docs.datomic.com/pull.html

hmadelaine14:06:54

@robert-stuttaford: yes of course, I should have proposed this solution. I was to focused on the code 😉

robert-stuttaford14:06:46

your suggestion isn’t at all wrong. it’s just pull is more suitable simple_smile

lboliveira14:06:30

@robert-stuttaford: thank you. I will use the pull api.

cmdrdats14:06:47

From the day of datomic videos, Stu mentioned that in practise they found they pretty much put ‘index’ on everything

robert-stuttaford14:06:05

you don’t need to index type ref or anything with unique on it

robert-stuttaford14:06:13

it’s redundant in both cases. already indexed

cmdrdats14:06:26

ah, ok - so it’s making a little extra schema..

robert-stuttaford14:06:51

yeah. no harm done, just no use either simple_smile

Lambda/Sierra14:06:16

leandro: EntityMaps (the return type from d/entity) are not Clojure maps. You can't assoc them. Instead, try d/pull, which returns real Clojure maps.

Lambda/Sierra14:06:44

oh, scrolling, whatever

lboliveira15:06:59

@stuartsierra: Thank you. Now I am using the pull api. Far better.

Lambda/Sierra15:06:06

You're welcome.