Skip to content

Commit ddbc8de

Browse files
get bulk by vol
1 parent e29a718 commit ddbc8de

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

montycat/store_classes/kv.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ async def delete_bulk(cls, bulk_keys: list = [], bulk_custom_keys: list = []):
205205
return await cls._run_query(query)
206206

207207
@classmethod
208-
async def get_bulk(cls, bulk_keys: list = [], bulk_custom_keys: list = [], limit: list = [], with_pointers: bool = False, key_included: bool = False, pointers_metadata: bool = False):
208+
async def get_bulk(
209+
cls, bulk_keys: list = [], bulk_custom_keys: list = [], limit: list = [], with_pointers: bool = False, key_included: bool = False, pointers_metadata: bool = False, volumes: list[str] = [], latest_volume: bool = False):
209210
"""
210211
Retrieve multiple keys in bulk. Custom keys can be converted and added to the bulk retrieval list.
211212
Additionally, a limit on the number of records to retrieve can be applied, and whether to include pointers
@@ -220,13 +221,19 @@ async def get_bulk(cls, bulk_keys: list = [], bulk_custom_keys: list = [], limit
220221
no limit is applied.
221222
with_pointers (bool, optional): If True, the query will include pointer information with the results.
222223
Default is False.
224+
key_included (bool, optional): If True, the query will include the keys in the results.
225+
Default is False.
226+
pointers_metadata (bool, optional): If True, the query will include metadata about pointers in the results.
227+
Default is False.
228+
volumes (list[str], optional): A list of volumes to retrieve. Default is an empty list.
229+
latest_volume (bool, optional): If True, the query will retrieve the latest volume. Default is False.
223230
224231
Returns:
225232
dict | str: Returns a dictionary of keys and their associated values if successful, or a string
226233
message if the retrieval fails or there is an error.
227234
228235
Raises:
229-
ValueError: If both `bulk_keys` and `bulk_custom_keys` are empty.
236+
ValueError: If both `bulk_keys` and `bulk_custom_keys` are empty and neither `volumes` nor `latest_volume` is specified.
230237
ValueError: If both `pointers_metadata` and `with_pointers` are True.
231238
"""
232239

@@ -237,12 +244,18 @@ async def get_bulk(cls, bulk_keys: list = [], bulk_custom_keys: list = [], limit
237244
bulk_custom_keys = convert_custom_keys(bulk_custom_keys)
238245
bulk_keys += bulk_custom_keys
239246

240-
if not bulk_keys:
241-
raise ValueError("No keys provided for retrieval.")
247+
selected_options = sum([
248+
bool(bulk_keys),
249+
bool(volumes),
250+
bool(latest_volume)
251+
])
252+
253+
if selected_options != 1:
254+
raise ValueError("Multiple conflicting options provided. Please provide exactly one of the following: keys, volumes, or latest volume.")
242255

243256
cls.command = "get_bulk"
244257
cls.limit_output = handle_limit(limit)
245-
query = convert_to_binary_query(cls, bulk_keys=bulk_keys, with_pointers=with_pointers, key_included=key_included, pointers_metadata=pointers_metadata)
258+
query = convert_to_binary_query(cls, bulk_keys=bulk_keys, with_pointers=with_pointers, key_included=key_included, pointers_metadata=pointers_metadata, volumes=volumes, latest_volume=latest_volume)
246259
return await cls._run_query(query)
247260

248261
@classmethod

montycat/store_classes/persistent.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,10 @@ async def update_value(cls, key: Union[str, None] = None, custom_key: Union[str,
9999
it will be converted to the appropriate format before updating.
100100
101101
Args:
102-
key (int | str, optional): The key whose associated value needs to be updated.
102+
key (int | str, optional): The key whose associated value needs to be updated.
103103
This can either be an integer or a string. Default is an empty string,
104104
which will be ignored if custom_key is provided.
105-
custom_key (str, optional): The custom key whose associated value needs to be updated.
105+
custom_key (str, optional): The custom key whose associated value needs to be updated.
106106
Default is an empty string.
107107
filters (dict): A dictionary of field-value pairs that need to be updated in the store.
108108
@@ -142,11 +142,13 @@ async def insert_bulk(cls, bulk_values: list):
142142
return await cls._run_query(query)
143143

144144
@classmethod
145-
async def get_keys(cls, limit: Union[list, int] = [], volumes: list = [], latest_volume: bool = False):
145+
async def get_keys(cls, limit: Union[list, int] = [], volumes: list[str] = [], latest_volume: bool = False):
146146
"""
147147
Args:
148148
Limit: A list of two integers that determine the range of keys to retrieve.
149149
Example: limit = [10, 20] will retrieve keys 10 to 20.
150+
volumes (list[str], optional): A list of volumes to retrieve. Default is an empty list.
151+
latest_volume (bool, optional): Whether to retrieve keys from the latest volume. Default is False.
150152
Returns:
151153
A list of keys in the store. Class 'str' if the get operation failed.
152154
"""
@@ -162,7 +164,14 @@ async def get_keys(cls, limit: Union[list, int] = [], volumes: list = [], latest
162164

163165
@classmethod
164166
async def create_keyspace(cls):
165-
167+
"""
168+
Creates a new keyspace in the store with the specified settings for persistence, distribution, caching, and
169+
compression.
170+
Returns:
171+
bool: True if the keyspace was created successfully, False otherwise.
172+
Raises:
173+
ValueError: If the keyspace is not set to be persistent.
174+
"""
166175
query = orjson.dumps({
167176
"raw": [
168177
"create-keyspace",

0 commit comments

Comments
 (0)