Skip to content

AkaBlur/py-simpledatastore

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Py-SimpleDataStore

A simple data storage solution to store small amounts of data in a file-based database.

Concepts

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

ID

  • 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

Content

  • Currently only string is supported
  • One ID can only have one specific string-list as content
    👉 No Duplicates with the same ID are allowed!

Storage Integrity

Integrity of the storage is validated through several steps:

  1. No duplicates inside ID file

  2. No duplicate IDs inside the storage itself (files with the same ID)

  3. Every ID inside the ID file has to have a file in storage

  4. Every ID inside the storage has to have an entry inside the ID file

  5. Each stored file has to have a hash that is valid for its stored content

Usage

Storage Creation

# storage path as pathlib.Path
storePath = pathlib.Path("mystore")
dataStore = SimpleDataStore(storePath)

Storage Deletion

Deletes the whole store including the files stored on disk.

SimpleDataStore.delete_store()

Helper functions

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

Storage access

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])

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages