hoops_ai.storage.datastorage.json_storage_handler
Classes
|
Handles the storage and retrieval of data using JSON files. |
- class hoops_ai.storage.datastorage.json_storage_handler.JsonStorageHandler(json_dir_path)
Bases:
DataStorageHandles the storage and retrieval of data using JSON files.
Each data_key is stored as a separate JSON file within a specified directory.
- Parameters:
json_dir_path (str)
- close()
Closes the JsonStorageHandler. Since JSON operations are stateless, there’s nothing to close.
- Return type:
None
- get_file_path(data_key)
Retrieves the file path for a given data key.
- get_group_for_array(array_name)
Determines which group an array belongs to based on the schema.
- get_keys()
Lists all data keys available in the JSON storage directory.
- Returns:
A list of data keys.
- Return type:
- get_schema()
Retrieves the schema definition for this storage instance.
- Returns:
The schema definition, or empty dict if no schema is set
- Return type:
- load_data(data_key)
Loads data from a JSON file using the specified key.
- Parameters:
data_key (str) – The key of the data to load.
- Returns:
The loaded data.
- Return type:
Any
- Raises:
KeyError – If the data_key does not exist.
ValueError – If the JSON data cannot be deserialized.
- load_metadata(key)
Loads metadata by key from the metadata JSON file. Supports nested keys using ‘/’ as a separator.
- save_data(data_key, data)
Saves data to a JSON file under the specified key.
- Parameters:
data_key (str) – The key under which to store the data.
data (Any) – The data to store.
- Raises:
ValueError – If the data cannot be serialized to JSON.
- Return type:
None
- save_metadata(key, value)
Saves metadata as a key-value pair into the metadata JSON file. If the file doesn’t exist, it will be created.
- Parameters:
key (str) – The metadata key, which can be a nested key using ‘/’ as a separator.
value (Any) – The metadata value (bool, int, float, string, list, or array).
- Return type:
None