Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to get enum value via Datomic pull syntax?

In the mbrainz sample data, the :artist/type is an enum. Is it possible to pull the value of the enum out of :db/ident and associate it as the value of the :artist/type key using pull syntax?

This is as close as I could get:

[:find (pull ?e [:artist/name {:artist/type [:db/ident]}])
 :where
 [?e :artist/name "Ray Charles"]
]

;;=> [[{:artist/name "Ray Charles", :artist/type {:db/ident :artist.type/person}}]]

Is it possible to use pull syntax to reshape the result into something like this?

;;=> [[{:artist/name "Ray Charles", :artist/type :artist.type/person}]]
like image 824
Upgradingdave Avatar asked Aug 05 '15 00:08

Upgradingdave


1 Answers

Was quite easy to do with postwalk

for any pulled :db/ident you can transform with this function

(defn flatten-ident [coll]
  (clojure.walk/postwalk
   (fn [item] (get item :db/ident item)) coll))
like image 67
Max Prokopov Avatar answered Sep 30 '22 13:09

Max Prokopov