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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 828885581129931761e4350d8b8ab757b5a64308ff70b73043adaa8997813f47 |
|
MD5 | f41980709b8213a2553687a15b864492 |
|
BLAKE2b-256 | 708b4f29a3b1298f72a34d3c1c80ef4fbe7774d0676dea19e805e1450ab61b77 |
Close
Hashes for mongoengine_softdelete-0.0.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c602e67978fbef154d53d0e5cf0d5d0477d9dc2582589a3a5ac1bc99bbe33f5b |
|
MD5 | b5847dbb93dd85508c407b81a1e3eae8 |
|
BLAKE2b-256 | 1e1fb9ff29c4ad11bdb8991eeb2026c44c1e7a8a999edeb539dc781d910e273e |