Storage Service is a Django + DRF package that help to work with model.
Project description
Storage Service
Storage Service is a Django + DRF package that help to work with model. Main advantage of this class is to provide bulk operations over the model data and upsert for single object with M2M relations.
Installation
Use the package manager pip to install storage-service.
pip install storage_service
Usage
from storage_service.storage import StorageService
from blogs.helpers import BlogHelper # optional
from blogs.serializers import BlogSerializer # drf package
class BlogService(StorageService):
def __init__(self):
super().__init__()
self.helper = BlogHelper # optional
self.model = BlogSerializer.Meta.model
self.create_serializer_class = BlogSerializer
self.get_serializer_class = BlogSerializer
self.unique_identifier: str = 'pk' # required unique model field
self.unique_identifiers: list = [] # in case when you need more unique model fiedls
Methods
-
def serialize(self, entities, many=False):- helps deserialize list of objects to dict. -
def get_next_id(self):- returns next model primary key. -
def get_by(self, key: str = '', value=None, serialize=True):- helps to retrieve model data by provided key & value parameters. If serialize is set toTruethen method will return deserialized model data. Otherwise will be returned object. -
def get_pk(self, pk: int = 0, serialize=False):- helps to retrieve model data by provided pk value. If serialize is set toTruethen method will return deserialized model data. Otherwise will be returned object. -
def delete_by(self, key: str = '', value=None):- helps to delete model data by provided key & value parameters. -
def set_identifiers(self, data)- is helper method for bulk type & upsert methods. Method to add identifiers as dict and to remove identifiers as default element. -
def indexed(elements=None, index: int = 0, retrieve: bool = False):- get and / or retrieve element at index. -
def upsert(self, data, parameters=None, many_to_many_clear: bool = True):- method to upsert a single object. Supporting M2M relations. Based onself.unique_identifier&self.unique_identifiers. -
def bulk_upsert(self, data, parameters=None, many_to_many_clear: bool = True)- method to bulk upsert multiple objects. Supporting M2M relations. Based onself.unique_identifier&self.unique_identifiers. -
def bulk_delete(self, data)- method to bulk delete multiple objects. -
def bulk_get_or_create(self, data):- method to bulk get or create multiple objects.
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file storage-service-0.0.2.tar.gz.
File metadata
- Download URL: storage-service-0.0.2.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
562d1869f7e23d6d50ecd14ccf3b47fae97bbfc536b8ce9aedf6e5ef0807a52a
|
|
| MD5 |
8c15f17237c7985d2bf286bdb29e2a52
|
|
| BLAKE2b-256 |
383c0ec25923324e33e5ba3449441b22b6bea1a1f324a781e3ee161e91ca2b66
|
File details
Details for the file storage_service-0.0.2-py3-none-any.whl.
File metadata
- Download URL: storage_service-0.0.2-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8344f7d851d21abae43dc1cd035403159a8674fbd83bd0b4161b224d25f27a
|
|
| MD5 |
4b59cd4052397248503a4128ab9ec0c8
|
|
| BLAKE2b-256 |
ce3b06f00274eb471acab49d73a93c9a669852513cab5666f161aa51841bd516
|