简体   繁体   English

在Rails应用程序下将Neo4j与PostgreSQL相结合

[英]Combining Neo4j with PostgreSQL under Rails application

We're building a Rails 3 app that supposed to use both Neo4j database and standard postgresql . 我们正在构建一个应该使用Neo4j数据库和标准postgresql的Rails 3应用程序。

What is the best way of combining those to work together? 将这些组合在一起的最佳方法是什么? We need them both to be ORM compatible and they need to behave well interacting each other (relationships with each other etc). 我们需要它们兼容ORM,并且它们需要彼此良好地相互作用(彼此之间的关系等)。

Thanks 谢谢

Use ActiveRecord for Postgresql as you would normally. 像往常一样使用ActiveRecord for Postgresql。 Add methods to the models that make calls to Neo4j and return IDs. 向调用Neo4j并返回ID的模型添加方法。

For a simple example: 举个简单的例子:

A User has Tags . 用户标签 The User model would have a " tags " method. 用户模型将具有“ 标签 ”方法。 It would call a cypher query or rest query that brought back IDs ([2, 3, 5]) of tags from the graph database. 它会调用一个cypher查询或rest查询,从图形数据库中返回标签的ID([2,3,5])。 Then I would load the proper tag object from postgres with a 然后我会用postgres从postgres加载正确的标签对象

Tag.find_all_by_id([2, 3, 5])

I think neoid provides the methods Max refers to in his answer . 我认为neoid提供了Max在他的回答中提到的方法。

From the GitHub repo: 来自GitHub回购:

Make your ActiveRecords stored and searchable on Neo4j graph database, in order to make fast graph queries that MySQL would crawl while doing them. 使您的ActiveRecords在Neo4j图形数据库上存储和搜索,以便进行MySQL在执行时可以抓取的快速图形查询。

Neoid to Neo4j is like Sunspot to Solr. 对Neo4j来说,Neoid就像Sunspot到Solr。 You get the benefits of Neo4j speed while keeping your schema on your plain old RDBMS. 您可以获得Neo4j速度的优势,同时将模式保留在普通的旧RDBMS上。

Your application will need to co-ordinate activity between the databases. 您的应用程序需要协调数据库之间的活动。

It can be valuable to use multiple DBs where you need their different features badly enough, but there's a big complexity cost to this, and you lose basic features like foreign keys. 使用多个DB可能很有价值,因为你需要不同的功能,但是这会有很大的复杂性,而且你会失去像外键这样的基本功能。

From the PostgreSQL side you can theoretically implement one side of foreign key relationships, preventing the deletion of records from within PostgreSQL when the remote side still exists, and preventing the insertion of records in PostgreSQL where the remote side does not exist. 从PostgreSQL方面,理论上可以实现外键关系的一方,防止在远程端仍然存在时从PostgreSQL中删除记录,并防止在远程端不存在的PostgreSQL中插入记录。 You would need to see if neo4j has similarly flexible user-defined triggers. 您需要查看neo4j是否具有类似灵活的用户定义触发器。

Even if it's possible, performance of foreign key enforcement is likely to be absolutely horrible. 即使有可能,外键执行的表现也可能是绝对可怕的。

To me, it does not make sense to choose to use multiple databases via a common abstraction layer. 对我来说,选择通过公共抽象层使用多个数据库是没有意义的。 The main reason you would choose simultaneous use of multiple DBs is to benefit from the different features of each, and abstraction layers like ORMs just tend to get in the way of that. 您选择同时使用多个DB的主要原因是从每个DB的不同功能中受益,而像ORM这样的抽象层往往会妨碍它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM