Sqlite3 Class#
- class expectmine.storage.stores.sqlite3_store.Sqlite3Store(step_name: str, persistent_path: Path, working_directory: Path, **kwargs: Dict[Any, Any])[source]#
Bases:
BaseStore- __init__(step_name: str, persistent_path: Path, working_directory: Path, **kwargs: Dict[Any, Any])[source]#
Creates an instance of the scoped storage. Each storage instance is scoped to an individual step.
- Parameters:
step_name (str) β Step name to which the storage should be scoped
persistent_path (Path) β The path which the storage can use to persist data.
working_directory (Path) β The path which the storage can use to create temporary files in for the user or pipeline to access.
- Example:
>>> BaseStore("hello", Path("path1"), Path("path2")) BaseStore
>>> BaseStore("", Path("path1"), Path("path2")) ValueError("Step name can not be empty.")
- Raises:
TypeError β If the arguments have the wrong type.
ValueError β If either step name or any of the paths are empty.
- delete(key: str)[source]#
Deletes the value associated to the given key.
- Parameters:
key (str) β The key to associate with the value. A key cannot be empty. Keys have a maximum length of 255 characters.
- Example:
>>> delete("hello") True
- Raises:
TypeError β If the arguments have the wrong type.
ValueError β If the key is empty or too long.
- exists(key: str) bool[source]#
Returns a boolean indicating if a given key exists.
- Parameters:
key (str) β The key to associate with the value. A key cannot be empty. Keys have a maximum length of 255 characters.
- Returns:
A boolean indicating if the key exists.
- Return type:
bool
- Example:
>>> exists("hello") True
>>> exists("unknown_key") False
- Raises:
TypeError β If the arguments have the wrong type.
ValueError β If the key is empty or too long.
- get(key: str, returning: Type[T]) T | None[source]#
Returns the value for a given key. If the key is not found it returns None instead. In case of a file, a path to the file is returned instead.
- Parameters:
key (str) β The key to associate with the value. A key cannot be empty. Keys have a maximum length of 255 characters.
returning (T) β The type of the returned object.
- Returns:
The object of the given key, None if the key does not exist.
- Return type:
T | None
- Example:
>>> get("hello", string) "World"
>>> get("list", list[int | str]) [1,2, "Hello"]
>>> get("file", Path) Path("hello.txt")
>>> get("unknown_key", dict) None
- Raises:
TypeError β If the arguments have the wrong type.
ValueError β If there is a type mismatch between returning and the returned value, or if the key is empty or too long.
- list() list[str][source]#
Returns a list with all the keys that live the given keyspace.
- Returns:
A list of all keys.
- Return type:
list[str]
- Example:
>>> list() []
>>> list() ["hello", "world"]
- put(key: str, value: object | Path)[source]#
Inserts the key value pair into the store. If it does already exist, the previous value is overwritten, when the new value is inserted. The put method can handle both objects and filepaths.
- Parameters:
key (str) β The key to associate with the value. A key cannot be empty. Keys have a maximum length of 255 characters.
value (object | Path) β The value (object or file) to store. The maximum size of an object is 25 MiB. The object needs to be Pickled. In case of a filepath the maximum size of the file is 100MiB.
- Example:
>>> put("hello", "World")
>>> put("file", Path("hello.txt"))
>>> put("", "World") ValueError("Key can not be empty")
- Raises:
TypeError β If the arguments have the wrong type.
ValueError β If either the key is empty or too long, the value is not pickleable or too big.