4

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

I'd like to have login and password stuff in a traditional db, and keep other graphy information in neo4j. I'm told neo4j is bad for things that need large graph traversals. Perhaps I'm wrong in needing this, but I have an instance where I'd like to say something like... "return a dict(person.x,person.y,person.z) from all nodes where type==person", and then feed that into the view of my index page.

I've seen related questions about ORMs with neo4j: ORM with Graph-Databases like Neo4j in Python

...and this about multiple DBs in Flask: http://packages.python.org/Flask-SQLAlchemy/binds.html

Specifically, I see this taking the form of my create statement writing to sqlite db connection and then writing a key from there to additional relational information in neo4j.

Community
  • 1
  • 1
Mittenchops
  • 18,633
  • 33
  • 128
  • 246

3 Answers3

0

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

Otherwise, you could also look at neomodel (https://github.com/robinedwards/neomodel). It's written for Django but should be usable in Flask too.

Nigel Small
  • 4,475
  • 1
  • 17
  • 15
0

I don't know about mixed backend models, but I think depending on your user count, you can use neo4j for your users, too. If you put the user nodes into an index, you can get all users without searching the graph.

If you find that this actually is a bottleneck, migrating it to a split storage should not be too difficult.

Thomas Fenzl
  • 4,342
  • 1
  • 17
  • 25
-1

It is not that hard to adapt neo4j-driver and py2neo to use eg. Flask-Login. I have use py2neo to that and worked well, but migrated now to neo4j-driver Downside is that i did not manage to get it working with eg SQLalchemy etc. Using a double backend solution is not a problem, in an earlier project i have used SQLalchemy with SQLite3 and PostgreSQL, Neo4j and redis together. Using that, i have found no issues other than some design issues.

Peter
  • 57
  • 5