With django-dbindexer you can use SQL features on NoSQL databases and abstract the differences between NoSQL databases. For example, if your database doesn't support case-insensitive queries (
istartswith, etc.) you can just tell the dbindexer which models and fields should support these queries and it'll take care of maintaining the required indexes for you. It's similar for JOINs. Tell the dbindexer that you would like to use in-memory JOINs for a specific query for example and the dbindexer will make it possible. Magically, previously unsupported queries will just work. Currently, this project is in an early development stage. The long-term plan is to support more complex JOINs and at least some simple aggregates, possibly even much more.
For installation see Get SQL features on NoSQL with django-dbindexer
How does django-dbindexer make unsupported field lookup types work?
For each filter you want to use on a field for a given model, django-dbindexer adds an additional field to that model. For example, if you want to use the
contains filter on a
CharField you have to add the following index definition:
django-dbindexer will then store an additional
ListField called 'idxf_<char_field_name>_l_contains' on
MyModel. When saving an entity, django-dbindexer will fill the
ListField with all substrings of the
CharField's reversed content i.e. if
'Jiraiya' then the
['J', 'iJ', 'riJ', 'ariJ' ..., 'ayiariJ']. When querying on that
contains, django-dbindexer delegates this filter using
startswith on the
ListField with the reversed query string i.e.
filter('idxf_<char_field_name>_l_contains'__startswith='ari') which matches the content of the list and gives back the correct result set. On App Engine
startswith gets converted to ">=" and "<" filters for example.
In the following is listed which fields will be added for a specific filter/lookup type:
__iexactusing an additional
__istartswithcreates an additional
CharField. Uses a
__endswithusing an additional
__iendswithusing an additional
__yearusing an additional
IntegerField``and a ``__exactquery
__monthusing an additional
__dayusing an additional
__week_dayusing an additional
__containsusing an additional
__icontainsusing an additional
__regexusing an additional
__iregexusing an additional
For App Engine users using djangoappengine this means that you can use all django field lookup types for example.
MongoDB users using django-mongodb-engine can benefit from this because case-insensitive filters can be handled as efficient case-sensitive filters for example.
For regex filters you have to specify which regex filter you would like to execute:
This will allow you to use the following filter:
django-dbindexer uses backends to resolve lookups. You can specify which backends to use via
BaseResolver is responsible for resolving lookups like
__regex for example.
InMemoryJOINResolver is used to resolve JOINs in-memory.
ConstantFieldJOINResolver uses denormalization in order to resolve JOINs. For more information see JOINs via denormalization for NoSQL coders, Part 1 is then done automatically by the
ConstantFieldJOINResolver for you. :)
First of all, you need to install django-autoload. Then you have to create a site configuration module which loads the index definitions. The module name has to be specified in the settings:
Now, there are two ways to load database index definitions in the
AUTOLOAD_SITECONF module: auto-detection or manual listing of modules.
Note: by default
AUTOLOAD_SITECONF is set to your
autodiscover will search for
dbindexes.py in all
INSTALLED_APPS and load them. It's like in django's admin interface. Your
AUTOLOAD_SITECONF module would look like this:
Alternatively, you can import the desired index definition modules directly: