Skip to main content

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.

PyPI - Version PyPI - Python Version


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.

TODO

  • multi queryset slice

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_multidatabase_queryset-0.9.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django_multidatabase_queryset-0.9.0.tar.gz.

File metadata

File hashes

Hashes for django_multidatabase_queryset-0.9.0.tar.gz
Algorithm Hash digest
SHA256 5c8c5527a914bdb1930887660f95d6a3f212acb964b9493efacce8de7547d903
MD5 e07e3733a761307923b87c832a238104
BLAKE2b-256 fbeea059514bf2bd3f8863fd544b69b70227d89cf726e6f81128735a89959983

See more details on using hashes here.

File details

Details for the file django_multidatabase_queryset-0.9.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_multidatabase_queryset-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 803d84449f7ff311d76fa317f08e2eeaa14d3d1420815d7635f3abf8f9c09517
MD5 2d4150a3e0cf5676c3748af5e47884ae
BLAKE2b-256 7f7ac0131d95c2c64f40e0b532a1f677c60d5804157c7ad9428b6efc39feb7ca

See more details on using hashes here.

Supported by

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