django-multidb
Configure different apps or models to different database instances.
Django settings
DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": data_dir / "default.sqlite3",
},
"db1": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": data_dir / "db1.sqlite3",
},
"db2": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": data_dir / "db2.sqlite3",
},
"db3": {
"ENGINE": "djongo",
"NAME": "db3",
}
}
Configure different models to different database instances.
DATABASE_ROUTERS = ["django_multidb.routers.DatabaseModelsRouter"]
DATABASE_MODELS_MAPPING = {"permission": "db1", "role": "db2"}
The Permission model uses db1, and the Role model uses db2. Run the migrate command to create tables.
python manage.py migrate --database=db1 # create permission
python manage.py migrate --database=db2 # create role
Configure different apps to different database instances.
DATABASE_ROUTERS = ["django_multidb.routers.DatabaseAppsRouter"]
DATABASE_APPS_MAPPING = {"authz": "db1", "order": "db2"}
The app authz uses db1 instance, and the order uses db2 instance. Run the migrate command to create tables. c
python manage.py migrate --database=db1 # create all tables for the authz app.
python manage.py migrate --database=db2 # Create all tables for the order app.
Tested association queries and deletions between different SQLite instances and MongoDB. More use cases can be referred to in the tests.
About the Queryset.filter method
Due to the involvement of cross-database instance querying, even direct associations across different database architectures, the filter method has been overridden.
First, query the IDs of data in the associated table and then perform a query on the main table using an IN condition with these IDs, rather than using JOIN syntax for the query.
Metadata
Release files for django-multidb 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| django_multidb-0.1.1.tar.gz | 6.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_multidb-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.3 kB
Release files / django_multidb-0.1.1.tar.gz
| Download URL | django_multidb-0.1.1.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c8f690afc9177cab694bbd0bf8514a9e455daed9565941bbc60bed581d257260
|
|
BLAKE2b-256 checksum How to use checksums |
df4358b4f650b709e1c8b3927d29364a59d8dbe5bdcadb1663c1a475acb38f22
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.9 Darwin/23.2.0
|
Release files / django_multidb-0.1.1-py3-none-any.whl
| Download URL | django_multidb-0.1.1-py3-none-any.whl |
|---|---|
| Size | 8.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11feda3690b5aa2e91aed09d11360ccdac938e06057d990d75553a57ddae2b4e
|
|
BLAKE2b-256 checksum How to use checksums |
9ea6686d73d220f8249b11e240bda724ee8299c449c070d8479af6cbf5b8685e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.7.1 CPython/3.10.9 Darwin/23.2.0
|