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.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8118f4762d4b1ca26e0eef93457121150baeb2c206fefc45fd2384bd86271aa1 |
|
MD5 | a5e7db3766bbc94212ef47a83bfe10cf |
|
BLAKE2b-256 | 38bbfb669181d5eb9d18e1f5ea7dad36059dd89533930bc986d8e23657c3d544 |
Close
Hashes for mongoengine_softdelete-0.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8e175512643dcee8935d18f031a77a71c0046dafdf2b8555257958d98d5d072 |
|
MD5 | ee965218963683c9fd9f708b9c7100aa |
|
BLAKE2b-256 | 6cbbaf9844174e8c2548b5a1c2b2d1165239aa4c5421bfe531a306c0c7a1d6cf |