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.
Configuration
- Add router to settings.py
DATABASE_ROUTERS = ['database_routing.PrimaryReplicaRouter']
- Configure 'default' and 'replica' connections in
settings.DATABASES
- 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
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
Built Distribution
File details
Details for the file django-database-routing-1.2.0.tar.gz
.
File metadata
- Download URL: django-database-routing-1.2.0.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f82c8edaa8df923d1a9f59fe1a103cd2162ec65dab371f7b5c2a181c315438f |
|
MD5 | 79b1221f84bd38640019e3f4e335e763 |
|
BLAKE2b-256 | 37a91b5deaa67e22cc84593397ff93f84fcbc4696645e2987bce545811e142b1 |
File details
Details for the file django_database_routing-1.2.0-py2.py3-none-any.whl
.
File metadata
- Download URL: django_database_routing-1.2.0-py2.py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.10.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2df5f95d74f120cb7c59fba7387387c023ae0c5266106b76c8e31bd7a8bedd43 |
|
MD5 | 86a616944dcfd9b7ca148c608cf47b04 |
|
BLAKE2b-256 | 54112a458138ff98ab5480aee57e1a8e7cccfe079bc2bc62689d56350b5c23c7 |