A simple data storage solution to store small amounts of data in a file-based database.
The storage consists of one single folder for all data files, e.g. something like:
~/my-storage
Inside the storage all data is stored in seperate files.
~/my-storage/1234-4163f83b7ab34f965ae128219c2fc692.dat
Each storage object has an unique ID to be referred to.
1234-4163f83b7ab34f965ae128219c2fc692.dat
Verification of the storage content is done via simple MD5 hashes.
1234-
4163f83b7ab34f965ae128219c2fc692.dat
- IDs are not generated by the storage
👉 They need to be managed from the outside - IDs have to be unique
int
- IDs are stored locally for storage verification inside the store folder as
_ID.dat
- Currently only
string
is supported - One
ID
can only have one specificstring
-list as content
👉 No Duplicates with the sameID
are allowed!
Integrity of the storage is validated through several steps:
-
No duplicates inside
ID
file -
No duplicate
ID
s inside the storage itself (files with the same ID) -
Every
ID
inside theID
file has to have a file in storage -
Every
ID
inside the storage has to have an entry inside theID
file -
Each stored file has to have a hash that is valid for its stored content
# storage path as pathlib.Path
storePath = pathlib.Path("mystore")
dataStore = SimpleDataStore(storePath)
Deletes the whole store including the files stored on disk.
SimpleDataStore.delete_store()
List IDs
idList: list[int]
idList = SimpleDataStore.list_IDs()
Check Integrity
Checks integrity of the store according to the set integrity rules for the storage.
Automatically corrects for errors.
SimpleDataStore.check_integrity()
Hashing function
Hashing function for the storage files.
SimpleDataStore.calc_hash(content: list[str]) -> str
Adding data
SimpleDataStore.add_storage_file(id: int, content: list[str])
Deleting data
SimpleDataStore.delete_storage_file(id: int)
Reading data
SimpleDataStore.read_storage_data(id: int) -> list[str]
Writing data
Writes data to a storage file.
SimpleDataStore.write_storage_data(id: int, content: list[str])
Appending data
Appends data to already existing data into a storage file.
SimpleDataStore.append_storage_data(id: int, content: list[str])