Upg*_*ave 7 clojure datalog datomic
在mbrainz示例数据中,:artist/type是枚举.是否可以将枚举的值拉出:db/ident并使用pull语法将其作为:artist/type键的值关联?
这是我能得到的最接近的:
[: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}}]]
Run Code Online (Sandbox Code Playgroud)
是否可以使用pull语法将结果重塑为类似的内容?
;;=> [[{:artist/name "Ray Charles", :artist/type :artist.type/person}]]
Run Code Online (Sandbox Code Playgroud)
我认为您无法按照您所寻求的方式使用 Pull API 来完成此操作。您可能会发现使用Tupelo Datomic库更容易:
(require '[tupelo.datomic :as td]
'[tupelo.core :refer [spyx]] )
(let [x1 (td/query-scalar :let [$ db-val]
:find [ ?e ]
:where [ [?e :artist/name "Ray Charles"] ] )
x2 (td/entity-map db-val x1)
]
(spyx x1)
(spyx x2)
)
Run Code Online (Sandbox Code Playgroud)
结果如下:
x1 => 17592186049074
x2 => {:艺术家/sortName“查尔斯,雷”,:艺术家/名称“雷·查尔斯”,:艺术家/类型:artist.type/person,:艺术家/国家:国家/美国,:艺术家/gid #uuid“ 2ce02909-598b-44ef-a456-151ba0a3bd70",:艺术家/startDay 23,:艺术家/endDay 10,:艺术家/startYear 1930,:艺术家/endMonth 6,:艺术家/endYear 2004,:艺术家/startMonth 9,:艺术家/性别:艺术家.性别/男}
因此 :artist/type 已经转换为 :db/ident 值,您可以将其从地图中拉出。