Skip to content

Commit

Permalink
chore: update store
Browse files Browse the repository at this point in the history
  • Loading branch information
iunary committed Apr 30, 2023
1 parent 6001a7b commit 9824f8a
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions burrowkv/burrowkv.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def set(self, key: str, value: str) -> None:
value (str): The value to associate with the key.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
"""
with self.__lock:
Expand All @@ -46,7 +46,7 @@ def get(self, key: str) -> Optional[str]:
if the key does not exist.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
>>> store.get('name')
'John'
Expand Down Expand Up @@ -76,7 +76,7 @@ def contains(self, key: str) -> bool:
bool: True if the key exists, False otherwise.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
>>> store.contains('name')
True
Expand All @@ -93,7 +93,7 @@ def keys(self) -> List[str]:
list: A list of keys.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
>>> store.keys()
['name']
Expand All @@ -108,7 +108,7 @@ def values(self) -> List[str]:
list: A list of values.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
>>> store.values()
['John']
Expand All @@ -123,7 +123,7 @@ def items(self) -> List[Tuple[str, str]]:
list: A list of (key, value) tuples.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> store.set('name', 'John')
>>> store.items()
[('name', 'John')]
Expand Down Expand Up @@ -160,17 +160,14 @@ def transaction(self):
performing multiple operations on the store.
Example:
>>> store = KeyValueStore()
>>> store = Burrowkv()
>>> with store.transaction():
... store.set('name', 'John')
... store.set('age', 30)
>>> store.get('name')
>>> store.get('age')
"""
try:
yield
finally:
self.__store.clear()
yield

def clear(self):
"""
Expand All @@ -190,3 +187,11 @@ def __len__(self) -> int:
int: The number of key-value pairs.
"""
return len(self.__store)

def __repr__(self) -> str:
"""Return the store representation
Returns:
str: JSON respresentation of key-value store
"""
return self.to_json()

0 comments on commit 9824f8a

Please sign in to comment.