Fork me on GitHub
Lone Ranger17:02:12

I couldn't find this in the documentation anywhere, I'm curious what the expected behavior of doing a pull on a composite tuple is. Would you expect back a map or a vector? i.e., based on the documentation, this makes sense to me, but I'm not sure if it matches with reality:

;; pseudo-data example

(d/q '[:find (pull ?e [*]) .
       [?e :db/id [:reg/semester+course+student [234561 345621 123456]]
  @conn)  ;;=> 
[{:db/id           234561
  :semester/year   2018
  :semester/season :fall}
 {:db/id    345621
  course/id "BIO-101"}
 {:db/id         123456
  :student/first "John"
  :student/last  "Doe"
  :student/email ""}]

Ivar Refsdal09:02:37

I would expect a map if you use the . notation in :find. Otherwise I would expect a 0 or 1 length set as the :reg/course+semester+student attribute is :db.unique/identity.

(defn db-id [lookup-ref]
  (d/q '[:find ?e .
         :in $ ?id-attr ?value
         [?e ?id-attr ?value]]
       (d/db conn)
       (first lookup-ref)
       (second lookup-ref)))

  (d/q '[:find (pull ?e [*]) .
         :in $ ?course-semester-student
         [?e :reg/course+semester+student ?course-semester-student]]
        (d/db conn)
       [(db-id [:course/id "BIO-101"])
        (db-id [:semester/year+season [2018 :fall]])
        (db-id [:student/email ""])]))
  ; =>
  ;{:db/id 17592186045422,
  ; :reg/course #:db{:id 17592186045419},
  ; :reg/semester #:db{:id 17592186045418},
  ; :reg/student #:db{:id 17592186045420},
  ; :reg/course+semester+student [17592186045419 17592186045418 17592186045420]}
The only thing I don't like with this is having to write and call the db-id function. Datomic should do this itself I think. Here is a working gist that demostrates this: Edit: The schema and basic data transactions is copied from

Lone Ranger20:02:26

Brilliant, thank you

🙂 4
Lone Ranger20:02:47

That’s exactly what I was looking for


In the Datomic query grammar is find-rel short for something? find-relation?


Yes. A relation is a set of same-typed tuples


Awesome. What does "same-typed" mean in this context?


each tuple is the same type?


I guess specific to datomic, each tuple slot corresponds to the same binding expression in the find


All this grammar means is you’ll get results like #{[x y z]…} not [x y z] (tuple) or [x x x] (collection) or x (scalar)


and none of this is supported on datomic cloud


> each tuple slot corresponds to the same binding expression in the find This makes sense to me.


> none of this None of what?


it doesn’t support any destructuring in :find


IOW “find-rel” is the only option


Got it! Thanks.