Soft delete for MongoEngine
Project description
MongoEngine Soft Delete
Make a document soft deletable.
Installation
Install mongoengine-softdelete
through pip as usual:
pip install mongoengine-softdelete
Usage
Here is an example on how to use a soft deletable document:
from mongoengine_softdelete.document import SoftDeleteNoCacheDocument
class IceCream(SoftDeleteNoCacheDocument):
meta = {
'collection': 'ice_cream',
'soft_delete': {'deleted': True},
'indexes': [ 'flavor' ],
'strict': False
}
flavor = fields.StringField(required=True)
color = fields.StringField(required=True)
price = fields.FloatField(default=0)
created_at = fields.DateTimeField()
# Declare the field used to check if the record is soft deleted
# this field must also be reported in the `meta['soft_delete']` dict
deleted = fields.BooleanField(default=False)
# Save a new document
ice = IceCream(flavor="Vanilla", color="White").save()
assert not ice.is_soft_deleted
# Mark the document as soft deleted
ice.soft_delete()
assert len(IceCream.objects()) == 0
assert ice.is_soft_deleted
# Soft undelete the document
ice.soft_undelete()
assert len(IceCream.objects()) > 0
assert not ice.is_soft_deleted
Tests
The test suit requires that you run a local instance of MongoDB on the standard
port and have pytest
installed.
You can run tests with the pytest
command or with make test
.
Linting is done with mypy
and pycodestyle
with the make lint
command.
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 mongoengine-softdelete-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fad64e73b409a702dc98ca5669c6f3399942ce11a36d18a9ca0a80200e0500c3 |
|
MD5 | e0a338a6f015766a1d23a00b363d5a8e |
|
BLAKE2b-256 | b8bea5d38d5aab36e77b9f456632dd914c325bc4ad9e4e81418c42f30b0f9fa1 |
Close
Hashes for mongoengine_softdelete-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be217c0504f730591e9c893229bfb3cdf03e03d5ed4b0d481cdb237a67174929 |
|
MD5 | a1f0ca9bbe66775e4ce4b3c41d26ac9a |
|
BLAKE2b-256 | c1405823cfea77d775a0aa8d07e02a5cd19ccd150c88e453f20ab27ddb3ed0ee |