Skip to main content

Provides primary-replica routing

Project description

django-database-routing

Provides Primary/Replica database router for Django. See https://docs.djangoproject.com/en/dev/topics/db/multi-db/#an-example for example implementation.

build

Configuration

  1. Add router to settings.py
DATABASE_ROUTERS = ['database_routing.PrimaryReplicaRouter']
  1. Configure 'default' and 'replica' connections in settings.DATABASES
  2. If needed you can force specific connections for some apps or models:
PRIMARY_REPLICA_ROUTING = {
  'my_app.MyModel': {
    'read': 'custom_connection',
    'write': 'custom_connection
  }
}

Forcing reading from primary

When transaction isolation level or replication lag causing bugs in your project, you can force your code to read all the data from default (or primary) database.

from database_routing import force_primary_read
@force_primary_read
def do_some_reads_and_updates():
    # All Django ORM queries are going to 'default' database here.
    # ...
    

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-database-routing-1.2.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

django_database_routing-1.2.0-py2.py3-none-any.whl (7.6 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-database-routing-1.2.0.tar.gz.

File metadata

File hashes

Hashes for django-database-routing-1.2.0.tar.gz
Algorithm Hash digest
SHA256 2f82c8edaa8df923d1a9f59fe1a103cd2162ec65dab371f7b5c2a181c315438f
MD5 79b1221f84bd38640019e3f4e335e763
BLAKE2b-256 37a91b5deaa67e22cc84593397ff93f84fcbc4696645e2987bce545811e142b1

See more details on using hashes here.

File details

Details for the file django_database_routing-1.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_database_routing-1.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 2df5f95d74f120cb7c59fba7387387c023ae0c5266106b76c8e31bd7a8bedd43
MD5 86a616944dcfd9b7ca148c608cf47b04
BLAKE2b-256 54112a458138ff98ab5480aee57e1a8e7cccfe079bc2bc62689d56350b5c23c7

See more details on using hashes here.

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