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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd4669564d4a35a3bf7b12a03ccc50343453d0c0dd5e829a3828366aa378002 |
|
MD5 | c7f81ece50e7024b8ae6f7a9a8722f39 |
|
BLAKE2b-256 | 293bcc62b6436ffe113d6953933640bf5d5f7dbbd4919161f90800f8c3824ac3 |
Close
Hashes for mongoengine_softdelete-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a8cc0632164fe8a0f55bb16ecc857fc26c61c6a458795b313b97ac3a73978f57 |
|
MD5 | 1ba712d4c5645f8275130d34e5e0380b |
|
BLAKE2b-256 | ab3d795416eaaf13dcdfa6822d3f3141ab7826b06921d332d5064603348c08c0 |