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
- Host: GitHub
- URL: https://github.com/dcramer/django-db-routes
- Owner: dcramer
- License: apache-2.0
- Created: 2014-02-07T21:27:21.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2014-02-07T21:42:51.000Z (almost 12 years ago)
- Last Synced: 2025-02-06T11:18:54.915Z (11 months ago)
- Language: Python
- Homepage:
- Size: 121 KB
- Stars: 20
- Watchers: 6
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
- License: LICENSE
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)