The cleanest way to do ORM for neo4j + sql in a python flask? One model from 2 databases

How to create one model that speaks with two databases in Flask, where one is, say, sqlite, and the other is neo4j specifically?

I would like to have a username and password in traditional db and store other graphic information in neo4j. I am told that neo4j is bad for things that require large graph workarounds. Maybe I'm wrong about that, but I have an instance where I would like to say something like ... " return a dict(person.x,person.y,person.z) from all nodes where type==person "and then enter this into the view of my index page.

I saw related questions about ORM with neo4j: ORM with graphical databases like Neo4j in Python

... and this applies to several databases in Flask: http://packages.python.org/Flask-SQLAlchemy/binds.html

In particular, I see that this takes the form of my create statement, which writes the sqlite db connection, and then writes the key to additional relational information from there to neo4j.

+4
source share
3 answers

I recently released OGM (Object-Graph Mapping) module for py2neo ( http://book.py2neo.org/en/latest/ogm.html ). This can help with what you are trying to do.

Otherwise, you can also look at neomodel ( https://github.com/robinedwards/neomodel ). This is written for Django, but should also be used in Flask.

0
source

I do not know about mixed backend models, but I think that depending on your number of users, you can also use neo4j for your users. If you put user nodes in the index, you can get all users without looking for a graph.

If you find that this is actually a bottleneck, moving it to shared storage should not be too complicated.

0
source

It is not so difficult to adapt the neo4j driver and py2neo for use, for example. Flask-Sign. I used py2neo for this and worked well, but now ported to neo4j-driver The disadvantage is that I was not able to get it to work, for example, SQLalchemy, etc. Using a dual backend solution is not a problem, in an earlier project I used SQLalchemy with SQLite3 and PostgreSQL, Neo4j and redis together. Using this, I did not find any problems other than some design problems.

-1
source

Source: https://habr.com/ru/post/1444879/


All Articles