An open API service indexing awesome lists of open source software.

https://github.com/dcramer/django-db-routes

work in progress
https://github.com/dcramer/django-db-routes

Last synced: about 2 months ago
JSON representation

work in progress

Awesome Lists containing this project

README

          

django-db-routes
================

The gist of the package is that we create a custom connection handler (``django.db.connections``) which
will map virtual shards to real databases. Databases end up being ``.shard``.

Partitioned Models
------------------

::

DATABASES = {
'mycluster': {
'NAME': 'mycluster',
'SHARDS': 1024,
'HOSTS': [
{'HOST': '192.168.0.100'},
{'HOST': '192.168.0.101'},
{'HOST': '192.168.0.102'},
{'HOST': '192.168.0.103'},
],
},
}

Extend the PartitionModel class when creating your models:

::

from django.db import models
from dbroutes.models import PartitionModel

class MyModel(PartitionModel):
user_id = models.PositiveIntegerField()

class Shards:
routing_key = 'user_id'
cluster = 'mycluster'

Query the nodes passing in your ``key``:

::

objects = MyModel.objects.filter(user_id=1)