This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-02-05
Channels
- # announcements (17)
- # architecture (5)
- # babashka (12)
- # beginners (155)
- # calva (18)
- # chlorine-clover (2)
- # cider (57)
- # circleci (2)
- # clojure (151)
- # clojure-europe (4)
- # clojure-gamedev (20)
- # clojure-italy (18)
- # clojure-nl (4)
- # clojure-norway (3)
- # clojure-spec (8)
- # clojure-uk (95)
- # clojurescript (70)
- # core-async (68)
- # css (3)
- # data-science (13)
- # datascript (1)
- # datomic (16)
- # docker (2)
- # figwheel-main (41)
- # fulcro (34)
- # graalvm (6)
- # graphql (7)
- # jobs (14)
- # joker (2)
- # kaocha (1)
- # leiningen (2)
- # malli (3)
- # midje (2)
- # overtone (1)
- # reagent (8)
- # reitit (6)
- # ring-swagger (1)
- # schema (2)
- # shadow-cljs (6)
- # spacemacs (3)
- # specter (5)
- # timbre (3)
- # uncomplicate (1)
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 [*]) .
:where
[?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 ""}]
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
:where
[?e ?id-attr ?value]]
(d/db conn)
(first lookup-ref)
(second lookup-ref)))
(d/q '[:find (pull ?e [*]) .
:in $ ?course-semester-student
:where
[?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:
https://gist.github.com/ivarref/dc2a5698cd0b791121bfadfa934bcd74#file-tuples2-clj-L79
Edit: The schema and basic data transactions is copied from https://docs.datomic.com/cloud/schema/schema-reference.html#tuplesThat’s exactly what I was looking for
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)