Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

django-database-routing

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

django-database-routing

Provides primary-replica routing

  • 1.2.0
  • PyPI
  • Socket score

Maintainers
1

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.
    # ...
    

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc