pythondjangoorientdbnon-relational-database

How can I use OrientDB with Django?


I am building a Django project that uses a relational DB (for development purposes SQLite) and an non-relational DB (OrientDB). This is my first time a using non-relational DB and I m having difficulty getting it set up with Django.

The use of OrientDB in my project is solely to keep track of friend relationships and friend-of-friend relationships, while all other user data is being stored in my relational DB.

I know I need to register the DB in my settings file. I am trying to do something like this:

#setting.py
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    },

    'friends': {
        'NAME': 'friends',
        'ENGINE': 'django.db.backends.orientdb',
        'USER': 'root',
        'PASSWORD': 'hello',
        'HOST': '',
        'PORT': '2480',
    }
}

When I do this, however, I get the error:

No module named 'django.db.backends.orientdb'

Is this backend module something I have to create myself or can I manually connect to the DB in my code whenever I need something specific done? For example, whenever someone creates a new user in my SQLite DB, can I use a Signal post_save to

  1. connect to OrientDb,
  2. create a friend instance in Orient DB, and
  3. disconnects from OrientDB?

It seems like there ought to be a much cleaner way of doing this.


Solution

  • This is almost certainly something you'll need to build yourself, though your use case doesn't sound like it requires a whole Django backend. A few manual queries might be enough.

    Django officially supports PostgreSQL, MySQL, SQLite, and Oracle. There are third-party backends for SAP SQL Anywhere, IBM DB2, Microsoft SQL Server, Firebird, and ODBC.

    There is an abandoned project that attempted to provide an OrientDB backend for Django, but it hasn't been updated in quite a long time and likely needs a lot of love:

    This project isn't maintained anymore, feel free to fork and keep it alive.

    No matter how you choose to proceed you should probably take a look at OrientDB's Python library.