如何使用neo4j实施修订? [英] How do I implement revisions with neo4j?

查看:55
本文介绍了如何使用neo4j实施修订?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个对象,我需要保留对其所做的所有更改的历史记录.我将如何使用 neo4j 来实现这一点?

I have an object and I need to keep a history of all changes made to it. How would I implement this using neo4j?

推荐答案

与RDBMS一样,这取决于您的域和数据查询要求.

As with a RDBMS, it would depend on your domain and data query requirements.

您的应用程序是否需要对对象的所有版本进行常规访问,或者通常仅对最新版本进行访问,而较旧的版本则可以通过当前版本访问?例如,维基百科上的页面.举例来说,假设我们有一个页面位于版本3上.然后可以按如下所示对其进行建模:

Does your application require regular access to all versions of the object or usually just to the most recent, with the older versions available via the current one? An example of this could be pages on Wikipedia. As as example, let's say we have a page which is on version 3. We could then model this as follows:

(pages)-[:PAGE]->(V3)-[:PREV]->(V2)-[:PREV]->(V1)
   ^               ^
   |               |
category        current
  node      version of page

在这里,只能看到当前版本构成主结构的一部分,但是您可能希望允许所有版本都构成该结构的一部分.在这种情况下,您可以使用关系属性来指示版本,并具有来自类别节点的所有页面版本链接:

Here, only the current version can be seen to form part of the main structure but you may wish to allow all versions to form part of that structure. In this case, you could use relationship properties to indicate the version and have all page versions link from the category node:

  (V1)
    ^
    |
[:PAGE(v=1)]
    |
 (pages)-[:PAGE(v=2)]->(V2)
    |
[:PAGE(v=3)]
    |
    v
  (V3)

在这里,您只需指定感兴趣的版本即可立即遍历页面的特定版本.

Here, you can immediately traverse to a particular version of the page by simply specifying the version in which you are interested.

第三个选项可能是您希望所有较旧的版本都与主结构完全分开.为此,您可以使用多个类别节点,一个用于(current_pages),另一个用于(old_pages).由于每个页面都被新版本取代,因此该页面与前一个类别不再链接,而是链接到后者.这将形成更多的归档"类型的系统,在该系统中,较早的版本甚至可以移至单独的数据库实例中.

A third option could be that you wish all older versions to be completely separate from the main structure. For this you could use multiple category nodes, one for (current_pages) and another for (old_pages). As each page is superseded by a new version, it becomes unlinked from the former category and instead linked to the latter. This would form more of an "archive" type of system where the older versions could even be moved into a separate database instance.

因此,您有这三个选择,还有我没想到的更多选择! Neo4j通过这种设计为您提供了极大的灵活性,而且绝对没有正确"的答案.但是,如果这些都不启发您,请发布更多有关您的域的信息,以便可以根据您的需求量身定制答案.

So you have these three options, plus more that I haven't thought of! Neo4j allows you great flexibility with this sort of design and there's absolutely no "right" answer. If none of these inspire you however, post a little more information about your domain so that the answer can be more tailored for your needs.

干杯, 尼日尔

这篇关于如何使用neo4j实施修订?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆