nectarstorage.sqlite module

class nectarstorage.sqlite.SQLiteCommon

Bases: object

This class abstracts away common sqlite3 operations.

This class should not be used directly.

When inheriting from this class, the following instance members must be defined:

  • sqlite_file: Path to the SQLite Database file

sql_execute(query: Tuple[str, Tuple], lastid: bool = False) int | None
sql_fetchall(query: Tuple[str, Tuple]) list
sql_fetchone(query: Tuple[str, Tuple]) Tuple | None
sqlite_file: Path | str
use_memory: bool
class nectarstorage.sqlite.SQLiteFile(*args: Any, **kwargs: Any)

Bases: object

This class ensures that the user’s data is stored in its OS preotected user directory:

OSX:

  • ~/Library/Application Support/<AppName>

Windows:

  • C:Documents and Settings<User>Application DataLocal Settings<AppAuthor><AppName>

  • C:Documents and Settings<User>Application Data<AppAuthor><AppName>

Linux:

  • ~/.local/share/<AppName>

Furthermore, it offers an interface to generated backups in the backups/ directory every now and then.

Note

The file name can be overwritten when providing a keyword argument profile.

clean_data(backupdir: str | Path = 'backups') None

Delete files older than 70 days

data_dir: Path
recover_with_latest_backup(backupdir: str | Path = 'backups') None

Replace database with latest backup

refreshBackup() None

Make a new backup

sqlite3_backup(backupdir: str | Path) None

Create timestamped database copy

sqlite3_copy(src: Path | str, dst: Path | str) None

Copy sql file from src to dst

sqlite_file: Path | str
storageDatabase: str
use_memory: bool
class nectarstorage.sqlite.SQLiteStore(*args, **kwargs)

Bases: SQLiteFile, SQLiteCommon, StoreInterface

The SQLiteStore deals with the sqlite3 part of storing data into a database file.

Note

This module is limited to two columns and merely stores key/value pairs into the sqlite database

On first launch, the database file as well as the tables are created automatically.

When inheriting from this class, the following three class members must be defined:

  • __tablename__: Name of the table

  • __key__: Name of the key column

  • __value__: Name of the value column

create() None

Create the new table in the SQLite database

delete(key: str) None

Delete a key from the store

Parameters:

value (str) – Value

exists() bool

Check if the database table exists

get(key: str, default: Any = None) Any

Return the key if exists or a default value

Parameters:
  • value (str) – Value

  • default (str) – Default value if key not present

items()

returns all items off the store as tuples

keys() a set-like object providing a view on D's keys
wipe() None

Wipe the store