1
0

json_db: add StoredList.clear() method

This commit is contained in:
ThomasV
2025-01-11 14:04:25 +01:00
parent 3ffcac87ac
commit ef08fb37a6

View File

@@ -88,7 +88,10 @@ def key_path(path, key):
else:
assert isinstance(x, str)
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:
@@ -209,6 +212,12 @@ class StoredList(list):
if self.db:
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):