05 November 2017
Datomic's Pull API provides a declarative way to make hierarchical and nested selections of information about entities. The 0.9.5656 release enhances the Pull API with a new :as clause that provides control over the returned keys.
As an example, imagine that you want information about Led Zeppelin's tracks from the mbrainz dataset. The following pull pattern navigates to the artist's tracks, using limit to return a single track:
;; pull expression
'[[:track/_artists :limit 1]]
=> #:track{:_artists
[#:db{:id 17592188757937}]}
;; pull pattern
'[{[:track/_artists :limit 1] [:track/name]}]
=> #:track{:_artists [#:track{:name "Black Dog"}]}
;; pull expression
'[{[:track/_artists :limit 1 :as "Tracks"]
[[:track/name :as "Name"]]}]
=> {"Tracks" [{"Name" "Black Dog"}]}