Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build_and_push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Configuration
PACKAGE_NAME="montycat"
VERSION="1.0.2"
VERSION="1.0.3"
PYPI_TOKEN="${PYPI_TOKEN:-}"

# Exit on any error
Expand Down
26 changes: 16 additions & 10 deletions montycat/store_classes/inmemory.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ async def clean_snapshots_for_keyspace(cls):

query = orjson.dumps({
"raw": [
"clean-snapshots-for-keyspace",
"store", cls.store,
"keyspace", cls.keyspace,
"clean-snapshots-for-keyspace",
"store", cls.store,
"keyspace", cls.keyspace,
],
"credentials": [cls.username, cls.password]
})

return await cls._run_query(query)

@classmethod
async def stop_snapshots_for_keyspace(cls):
"""
Expand All @@ -67,7 +67,7 @@ async def stop_snapshots_for_keyspace(cls):
})

return await cls._run_query(query)

@classmethod
async def insert_custom_key(cls, custom_key: str, expire_sec: int = 0):
"""
Expand All @@ -79,13 +79,13 @@ async def insert_custom_key(cls, custom_key: str, expire_sec: int = 0):
"""
if not custom_key:
raise ValueError("No custom key provided for insertion.")

custom_key_converted = convert_custom_key(custom_key)
cls.command = "insert_custom_key"

query = convert_to_binary_query(cls, key=custom_key_converted, expire_sec=expire_sec)
return await cls._run_query(query)

@classmethod
async def insert_custom_key_value(cls, custom_key: str, value: dict, expire_sec: int = 0):
"""
Expand All @@ -95,7 +95,7 @@ async def insert_custom_key_value(cls, custom_key: str, value: dict, expire_sec:
expire_sec: The number of seconds before the inserted value expires.
Returns:
True if the insert operation was successful. Class 'str' if the insert operation failed.

"""
if not value:
raise ValueError("No value provided for insertion.")
Expand Down Expand Up @@ -185,8 +185,8 @@ async def get_keys(cls, volumes: list = [], latest_volume: bool = False):
A list of keys in the store. Class 'str' if the get operation failed.
"""

if latest_volume and len(volumes) > 0:
raise ValueError("Select either latest volume or volumes list, not both.")
if not latest_volume and not volumes:
raise ValueError("Please provide keys or volumes/latest volume.")

cls.command = "get_keys"

Expand All @@ -195,6 +195,12 @@ async def get_keys(cls, volumes: list = [], latest_volume: bool = False):

@classmethod
async def create_keyspace(cls):
"""
Create a keyspace in the store.

Returns:
True if the keyspace was created successfully. Class 'str' if the keyspace creation failed.
"""

query = orjson.dumps({
"raw": [
Expand Down
16 changes: 5 additions & 11 deletions montycat/store_classes/kv.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,24 +234,19 @@ async def get_bulk(

Raises:
ValueError: If both `bulk_keys` and `bulk_custom_keys` are empty and neither `volumes` nor `latest_volume` is specified.
ValueError: If both `pointers_metadata` and `with_pointers` are True.
"""

if pointers_metadata and with_pointers:
raise ValueError("You select both pointers value and pointers metadata. Choose one")

if len(bulk_custom_keys) > 0:
bulk_custom_keys = convert_custom_keys(bulk_custom_keys)
bulk_keys += bulk_custom_keys

selected_options = sum([
bool(bulk_keys),
bool(volumes),
bool(latest_volume)
bool(volumes and len(volumes) > 0) or latest_volume or bool(limit and len(limit) > 0 and (limit[0] != 0 or limit[1] != 0)),
])

if selected_options != 1:
raise ValueError("Multiple conflicting options provided. Please provide exactly one of the following: keys, volumes, or latest volume.")
raise ValueError("Please provide keys or volumes/latest volume or limit.")

cls.command = "get_bulk"
cls.limit_output = handle_limit(limit)
Expand Down Expand Up @@ -279,7 +274,7 @@ async def update_bulk(cls, bulk_keys_values: dict = {}, bulk_custom_keys_values:
ValueError: If neither `bulk_keys_values` nor `bulk_custom_keys_values` is provided.
"""

if not bulk_keys_values:
if not bulk_keys_values and not bulk_custom_keys_values:
raise ValueError("No key-value pairs provided for update.")

if len(bulk_custom_keys_values) > 0:
Expand Down Expand Up @@ -324,6 +319,8 @@ async def lookup_values_where(cls, limit: Union[int, list] = 0, with_pointers: b
Args:
limit (int, optional): The maximum number of results to return. If 0, no limit is applied. Default is 0.
with_pointers (bool, optional): If True, the query will include pointers in the result. Default is False.
key_included (bool, optional): If True, the query will include the keys in the result. Default is False.
pointers_metadata (bool, optional): If True, the query will include metadata about the pointers. Default is False.
filters (dict): The filtering criteria for the lookup. These are field-value pairs that the values should match.

Returns:
Expand All @@ -333,9 +330,6 @@ async def lookup_values_where(cls, limit: Union[int, list] = 0, with_pointers: b
ValueError: If no filters are provided.
"""

if pointers_metadata and with_pointers:
raise ValueError("You select both pointers value and pointers metadata. Choose one")

if schema:
cls.schema = str(schema)
else:
Expand Down
4 changes: 2 additions & 2 deletions montycat/store_classes/persistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ async def get_keys(cls, limit: Union[list, int] = [], volumes: list[str] = [], l
A list of keys in the store. Class 'str' if the get operation failed.
"""

if latest_volume and len(volumes) > 0:
raise ValueError("Select either latest volume or volumes list, not both.")
if not volumes and not latest_volume and not limit and (not isinstance(limit, list) or len(limit) != 2 or (limit[0] == 0 and limit[1] == 0)):
raise ValueError("Please provide keys or volumes/latest volume or limit.")

cls.limit_output = handle_limit(limit)
cls.command = "get_keys"
Expand Down