Round-robin standbydb router for Django.
Project description
``multidb`` provides two Django database routers useful in master-standby
deployments.
MasterStandbyRouter
-----------------
With ``multidb.MasterStandbyRouter`` all read queries will go to a standby
database; all inserts, updates, and deletes will go to the ``default``
database.
First, define ``STANDBY_DATABASES`` in your settings. It should be a list of
database aliases that can be found in ``DATABASES``::
DATABASES = {
'default': {...},
'standby-1': {...},
'standby-2': {...},
}
STANDBY_DATABASES = ['standby-1', 'standby-2']
Then put ``multidb.MasterStandbyRouter`` into DATABASE_ROUTERS::
DATABASE_ROUTERS = ('multidb.MasterStandbyRouter',)
The standby databases will be chosen in round-robin fashion.
If you want to get a connection to a standby in your app, use
``multidb.get_standby``::
from django.db import connections
import multidb
connection = connections[multidb.get_standby()]
Running the Tests
-----------------
To run the tests, you'll need to install the development requirements::
pip install -r requirements.txt
./run.sh test
deployments.
MasterStandbyRouter
-----------------
With ``multidb.MasterStandbyRouter`` all read queries will go to a standby
database; all inserts, updates, and deletes will go to the ``default``
database.
First, define ``STANDBY_DATABASES`` in your settings. It should be a list of
database aliases that can be found in ``DATABASES``::
DATABASES = {
'default': {...},
'standby-1': {...},
'standby-2': {...},
}
STANDBY_DATABASES = ['standby-1', 'standby-2']
Then put ``multidb.MasterStandbyRouter`` into DATABASE_ROUTERS::
DATABASE_ROUTERS = ('multidb.MasterStandbyRouter',)
The standby databases will be chosen in round-robin fashion.
If you want to get a connection to a standby in your app, use
``multidb.get_standby``::
from django.db import connections
import multidb
connection = connections[multidb.get_standby()]
Running the Tests
-----------------
To run the tests, you'll need to install the development requirements::
pip install -r requirements.txt
./run.sh test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Close
Hashes for django-standbydb-router-0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b40dbcb66e687e32a8555d6a1be62864d6ae4074560c0acb12a3a83e81e267a |
|
MD5 | bc4b5bd5f23ceebdf5dbaa515cce562b |
|
BLAKE2b-256 | 1421f392314d91918842f7e309a619a2274fbc58a80d0018b7ab81a293d6d971 |