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.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fecd609875ab6841b63eb67d3d898abcdd0bdfaba40cf57b836d233a358411c9 |
|
MD5 | 1e6bfce5033a41129f54ec2d5a4f8f6d |
|
BLAKE2b-256 | 7f9dad464c33d77ffda7522991575b8272e50be80d606ce720fc963a2966389e |
Close
Hashes for mongoengine_softdelete-0.0.10-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f5da5ac33199b24c504323e25e9d304ac0422ccb069a41cf0f556b7439a97904 |
|
MD5 | 888304172ac022c340044b9ce6504660 |
|
BLAKE2b-256 | fa73bc22812843bdb158c2b17723852a6e2355eac708b57f95b1122d93c3835a |