Skip to main content

Round-robin multidb router for Django 1.2.

Project description

With multidb.MasterSlaveRouter all read queries will go to a slave database; all inserts, updates, and deletes will do to the default database.

First, define SLAVE_DATABASES in your settings. It should be a list of database aliases that can be found in DATABASES:

DATABASES = {
    'default': {...},
    'shadow-1': {...},
    'shadow-2': {...},
}
SLAVE_DATABASES = ['shadow-1', 'shadow-2']

Then put multidb.MasterSlaveRouter into DATABASE_ROUTERS:

DATABASE_ROUTERS = ('multidb.MasterSlaveRouter',)

The slave databases will be chosen in round-robin fashion.

If you want to get a connection to a slave in your app, use multidb.get_slave:

from django.db import connections
import multidb

connection = connections[multidb.get_slave()]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-multidb-router-0.3.tar.gz (3.3 kB view details)

Uploaded Source

File details

Details for the file django-multidb-router-0.3.tar.gz.

File metadata

File hashes

Hashes for django-multidb-router-0.3.tar.gz
Algorithm Hash digest
SHA256 5a22235a683a662722ec80c7e666ccb1622b0628476e89eede098eb3724dd5dd
MD5 0071dcfbb31fc705430a529bdfcb99fa
BLAKE2b-256 f826f73b416371689e6fcde768de9131f26914fbedce4cd4e319acde5c44832d

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page