diff --git a/docs/commands.html b/docs/commands.html index 6871d36..d1cae99 100644 --- a/docs/commands.html +++ b/docs/commands.html @@ -50,7 +50,7 @@

Current Commands

DREM name → Remove a dict and all of its pairs (available since 0.2.2)

DPOP name key → Remove one key-value in a dict (available since 0.2.2)

DMERGE name1 name2 name3 → Merge name1 and name2 into a new dict: name3 (available since 0.7.3) -

DELDB → Delete everything from the database (available since 0.2.1)

+

DELDB andfile → Delete everything from the database, set andfile to True to delete the database file too.(available since 0.2.1)

DUMP → Save the database from memory to a file specified in LOAD (available since 0.3)

Suggestions

If you would like to suggest a command, you can create an issue on GitHub.

diff --git a/pickledb.py b/pickledb.py index 8ff5552..855755c 100644 --- a/pickledb.py +++ b/pickledb.py @@ -47,13 +47,13 @@ def load(location, auto_dump, sig=True): class PickleDB(object): - key_string_error = TypeError('Key/name must be a string!') - + key_string_error = TypeError('Key/name must be a string!') def __init__(self, location, auto_dump, sig): '''Creates a database object and loads the data from the location path. If the file does not exist it will be created on the first update. ''' self.load(location, auto_dump) + self.__location__ = location self.dthread = None if sig: self.set_sigterm_handler() @@ -63,11 +63,11 @@ def __getitem__(self, item): return self.get(item) def __setitem__(self, key, value): - '''Sytax sugar for set()''' + '''Syntax sugar for set()''' return self.set(key, value) def __delitem__(self, key): - '''Sytax sugar for rem()''' + '''Syntax sugar for rem()''' return self.rem(key) def set_sigterm_handler(self): @@ -290,9 +290,11 @@ def dmerge(self, name1, name2): self._autodumpdb() return True - def deldb(self): - '''Delete everything from the database''' + def deldb(self, andfile = False): + '''Delete everything from the database, optionally delete the database file''' self.db = {} self._autodumpdb() + if andfile: + os.remove(self.__location__) return True diff --git a/tests.py b/tests.py index 7db5a6d..88babf9 100644 --- a/tests.py +++ b/tests.py @@ -108,6 +108,14 @@ def test_not_dexists(self): assert x is False self.db.drem('dict') + def test_location(self): + assert self.db.__location__ == 'tests.db' + self.db.dump() + self.db.deldb() + from pickledb import os + assert os.path.exists(self.db.__location__) + self.db.deldb(True) + assert not os.path.exists(self.db.__location__) if __name__ == "__main__": tests = TestClass()