使用 Datomic,我试图考虑如何在列表中嵌套列表?
一个示例 Clojure 数据结构将是某种东西(见图1)。我知道 Datomic 有引用的概念(例如在图 2 中)。但那些看起来像标量类型,而不是对象(本身)。
[{:id 0,
:symbol DDD,
:company 3D Systems Corporation,
:price-difference 1.3100000000000023,
:event-list [{high 35.11,
tickerId 0,
WAP 34.491,
open 35.07,
date 20130426,
count 3403,
low 33.8,
hasGaps false,
close 34.53,
field historicalData,
volume 8667,
type historicalData}]}]
图。1
{:db/id #db/id[:db.part/db]
:db/ident :district/region
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db/doc "A district region enum value"
:db.install/_attribute :db.part/db}
;; district/region enum values
[:db/add #db/id[:db.part/user] :db/ident :region/n]
[:db/add #db/id[:db.part/user] :db/ident :region/ne]
[:db/add #db/id[:db.part/user] :db/ident :region/e]
[:db/add #db/id[:db.part/user] :db/ident :region/se]
[:db/add #db/id[:db.part/user] :db/ident :region/s]
[:db/add #db/id[:db.part/user] :db/ident :region/sw]
[:db/add #db/id[:db.part/user] :db/ident :region/w]
[:db/add #db/id[:db.part/user] :db/ident :region/nw]
图2
[编辑]
其实,我想我可能在这里找到了答案。我正在浏览Day-Of-Datomic代码库,并找到了下面的示例。但是我仍然不清楚:comments命名空间与:comment/body(或:comment/author)命名空间的明确联系。Datomic 是否仅使用约定将:comments链接到:comment?
;; comments
[{:db/id #db/id[:db.part/db]
:db/ident :comments
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/many
:db/isComponent true
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :comment/body
:db/valueType :db.type/string
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}
{:db/id #db/id[:db.part/db]
:db/ident :comment/author
:db/valueType :db.type/ref
:db/cardinality :db.cardinality/one
:db.install/_attribute :db.part/db}]
图。1