Round-robin standbydb router for Django.
Project description
``standby`` provides a Django database router useful in master-standby deployments.
MasterStandbyRouter
-----------------
With ``standbydb.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 ``standbydb.MasterStandbyRouter`` into DATABASE_ROUTERS::
DATABASE_ROUTERS = ('standbydb.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
``standbydb.get_standby``::
from django.db import connections
import standbydb
connection = connections[standbydb.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
MasterStandbyRouter
-----------------
With ``standbydb.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 ``standbydb.MasterStandbyRouter`` into DATABASE_ROUTERS::
DATABASE_ROUTERS = ('standbydb.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
``standbydb.get_standby``::
from django.db import connections
import standbydb
connection = connections[standbydb.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
File details
Details for the file django-standbydb-router-0.2.tar.gz
.
File metadata
- Download URL: django-standbydb-router-0.2.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
77d425368a9f328701a5757371e9666cc63f2c0e2bb8f8f88177a311ab0d2cb6
|
|
MD5 |
13cc5f817ce99579ef5fd4f2a0b83652
|
|
BLAKE2b-256 |
e2fda035988d77eadb76043bbeb0e64a0c1903ca88ce04dfe67e427b599ae0b2
|