我已经阅读了文档,并且正在为以下情况而苦苦挣扎(可能我正在考虑使用neo4j和hyperedges,这就是为什么我在这里可以清楚考虑的原因:]
假设我要为以下实体建模::person
(具有某些属性,例如:name
,id
等),:school
(再次具有某些属性)school
与对象之间的关系person
可能类似于:student
或:teacher
。而且这可能会随着时间的流逝而变化(一个人可能与学校无关,以后是:student
,以后可能是:teacher
)
[:person
为:student
时,将有一个学生ID,而作为:teacher
它将有另一个ID,请说出教师ID。
所以,我应该有:
:person/name 'John'
:school/id 'SCHOOL-1'
:student/name 'John'
:student/school 'SCHOOL-1'
?我应该如何将信息包括为student-id
,如果还有更多学校,该怎么办?
但是现在,在我看来,这些实体之间的关系是一个超边缘(这就是为什么我提到neo4j的原因)。而且我不知道建模的最佳方法是原子学。
提前感谢
~/io.tupelo.demo/datomic > lct
Java HotSpot(TM) 64-Bit Server VM warning: Options -Xverify:none and -noverify were deprecated in JDK 13 and will likely be removed in a future release.
lein test _bootstrap
-------------------------------
Clojure 1.10.1 Java 13
-------------------------------
lein test tst.tupelo.datomic.bond
Ran 2 tests containing 35 assertions.
0 failures, 0 errors.
以上内容适用于Datomic Free版本,因此您甚至不需要付费许可证即可开始使用。
在“邦德”示例中,角色可能具有多个武器,这些武器被建模为一组:
; Create some antagonists and load them into the db. We can specify some of the ; attribute-value pairs at the time of creation, and add others later. Note that ; whenever we are adding multiple values for an attribute in a single step (e.g. ; :weapon/type), we must wrap all of the values in a set. Note that the set ; implies there can never be duplicate weapons for any one person. As before, ; we immediately commit the new entities into the DB. (td/transact *conn* (td/new-entity { :person/name "James Bond" :location "London" :weapon/type #{ :weapon/gun :weapon/wit } } ) (td/new-entity { :person/name "M" :location "London" :weapon/type #{ :weapon/gun :weapon/guile } } ) (td/new-entity { :person/name "Dr No" :location "Caribbean" :weapon/type :weapon/gun } ))