Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Datomic pull expression

I was reading about the Datomic pull syntax here:

http://docs.datomic.com/pull.html

And it explains under wildcard that a pattern like [*] will pull an entity and recursively pulls its entity attributes. Direct quote:

The wildcard specification * pulls all attributes of an entity, and recursively pulls any component attributes:

;; pattern
[*]

;; result
{:release/name "The Concert for Bangla Desh",
 :release/artists [{:db/id 17592186049854}],
 :release/country {:db/id 17592186045504},
 :release/gid #uuid "f3bdff34-9a85-4adc-a014-922eef9cdaa5",
 :release/day 20,
 :release/status "Official",
 :release/month 12,
 :release/artistCredit "George Harrison",
 :db/id 17592186072003,
 :release/year 1971,
 :release/media
 [{:db/id 17592186072004,
   :medium/format {:db/id 17592186045741},
   :medium/position 1,
   :medium/trackCount 2,
   :medium/tracks
   [{:db/id 17592186072005,
     :track/duration 376000,
     :track/name "George Harrison / Ravi Shankar Introduction",
     :track/position 1,
     :track/artists [{:db/id 17592186048829} {:db/id 17592186049854}]}
    {:db/id 17592186072006,
     :track/duration 979000,
     :track/name "Bangla Dhun",
     :track/position 2,
     :track/artists [{:db/id 17592186048829}]}]}
  ...
  ]}

However, when I try this myself I only get db/id values for ref types. I have to basically call out any ref type in a more verbose way in the pull expression, with something like this:

[* {:content/type [:db/ident] :content/locales [:db/ident] :content/groups [*]}]

And that's not even actually the end of it, because :content/groups itself has ref types inside of it. Did the behavior of wildcarding change at some point and the docs are not up to date? Or am I doing something wrong? Is there a better (more concise) way to go about saying, "just recursively pull it all in"?

like image 768
Kevin Avatar asked Feb 19 '26 23:02

Kevin


1 Answers

The wildcard in a pull expression only populates component attributes. That is, attributes with :db/isComponent true in the schema.

Looking at the mbrainz schema, only :release/media and :medium/tracks are component attributes, so they would be the only ones populated with a [*] pull pattern.

If your data model includes hierarchal reference chains (i.e. :person/friend as a reference to any person, who may also have friends referenced), you can define recursive pull patterns and specify their recursive depth (or use ... for unbounded).

This topic is also discussed on the Datomic Google Group, and includes a link to an example recursive pull pattern.

like image 165
Marshall Avatar answered Feb 25 '26 06:02

Marshall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!