Skip to main content

Provides primary-replica routing and force primary context manager for Django

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.1.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

django_database_routing-1.1.1-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

  • Download URL: django-database-routing-1.1.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for django-database-routing-1.1.1.tar.gz
Algorithm Hash digest
SHA256 aa858af59b5947b7db86dd6e39795b71b1b521d9ab5d38e643bb5351dd966848
MD5 fb021400e3076f8b508eef8afb0a640d
BLAKE2b-256 fa6d7172a36882956e56edeff15bb33e7d8de6fcd5c2b68e90bff041cc8f9bdb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: django_database_routing-1.1.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for django_database_routing-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 959bcc12754591e717967b867af73c2d02b20742502530583d0f42f9401c1032
MD5 34c712f215775b8d8fdaa5e54cedf4d3
BLAKE2b-256 9fec7573b80de4e4899440302859e29e25afed1228c9de7f17e10fca9010e08c

See more details on using hashes here.

Supported by

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