json_db: add StoredList.clear() method
This commit is contained in:
@@ -88,7 +88,10 @@ def key_path(path, key):
|
|||||||
else:
|
else:
|
||||||
assert isinstance(x, str)
|
assert isinstance(x, str)
|
||||||
return x
|
return x
|
||||||
return '/' + '/'.join([to_str(x) for x in path + [to_str(key)]])
|
items = [to_str(x) for x in path]
|
||||||
|
if key is not None:
|
||||||
|
items.append(to_str(key))
|
||||||
|
return '/' + '/'.join(items)
|
||||||
|
|
||||||
|
|
||||||
class StoredObject:
|
class StoredObject:
|
||||||
@@ -209,6 +212,12 @@ class StoredList(list):
|
|||||||
if self.db:
|
if self.db:
|
||||||
self.db.add_patch({'op': 'remove', 'path': key_path(self.path, '%d'%n)})
|
self.db.add_patch({'op': 'remove', 'path': key_path(self.path, '%d'%n)})
|
||||||
|
|
||||||
|
@locked
|
||||||
|
def clear(self):
|
||||||
|
list.clear(self)
|
||||||
|
if self.db:
|
||||||
|
self.db.add_patch({'op': 'replace', 'path': key_path(self.path, None), 'value':[]})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class JsonDB(Logger):
|
class JsonDB(Logger):
|
||||||
|
|||||||
Reference in New Issue
Block a user