No project description provided
Project description
django-multidatabase-queryset
Use multi database as one.
It's a common scenario that you want to
store hot data in the default database (using SSD) and
store cold data in the db_cold database (using HDD).
You want to use it like normal queryset without considering it.
Table of Contents
Usage
# add django_multidatabase_queryset to your project apps
INSTALLED_APPS = [
...
"django_multidatabase_queryset",
]
# inherit the django_multidatabase_queryset.models.MultiDataBaseModel, set the database used
class UserAction(MultiDataBaseModel):
DATABASES = ["default", "db_cold"]
type = models.TextField(default="")
detail = models.JSONField(default=dict)
# Use the objects as normal objects
data1 = UserAction(id=1, type="type4")
data1.save(using="default")
data2 = UserAction(id=2, type="type3")
data2.save(using="db_cold")
data3 = UserAction(id=3, type="type1")
data3.save(using="db_cold")
order_qs = UserAction.objects.order_by(
"type", "pk")
data = list(order_qs)
LOGGER.info(data)
self.assertEqual(data[0].type, "type1")
self.assertEqual(data[1].type, "type3")
self.assertEqual(data[2].type, "type4")
self.assertEqual(order_qs.count(), 3)
Installation
pip install django-multidatabase-queryset
License
django-multidatabase-queryset
is distributed under the terms of the MIT license.
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
Close
Hashes for django_multidatabase_queryset-0.4.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29a91d986fd6799a2afe2a8e9a0b942163184a6d9d47111dd32a18898e16280b |
|
MD5 | d3ca3d1f3484a64aa770197cb7f018a9 |
|
BLAKE2b-256 | 8cfd548ade220b00d73a0676f4ec015668aa8f2dc015dc48b4f5c3a93e69deb9 |
Close
Hashes for django_multidatabase_queryset-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f8fbf8e89f337bfd39f5891c636827f3c15a194ab84e982152e863c21d95c3c3 |
|
MD5 | 633d213dc0cc3ccee3fb0ca3e683263a |
|
BLAKE2b-256 | fb87ec13f8243f12823a4add2c4968b19c1a5656bb6da75b418c90c143d8ddd8 |