class documentation

Storage driver class for TinyDB that implements a buffered disk write.

Method __init__ Initialization of the storage driver.
Method close Write any dirty database files and close all handles.
Method read Read the current state.
Method write Write the current state of the database to the storage.
Class Variable __slots__ Define slots for instance variables.
Method _fileWriter Worker for the file writer thread.
Instance Variable _changed Indicator that the write buffer is dirty and needs to be written.
Instance Variable _data The actual database data, which is also strored in memory as a buffer.
Instance Variable _running Indicating that the database is open and in use.
Instance Variable _shutdownLock Internal lock when shutting down the database.
Instance Variable _shutting_down Indicator that the database is closing. This is different from _running.
Instance Variable _writeDelay Time to wait before writing a changed database buffer, in seconds.
Instance Variable _writeEvent Event instance to notify when a write happened.
def __init__(self, path: str, create_dirs: bool = False, encoding: str = None, access_mode: str = 'r+', write_delay: int = 1, **kwargs: Any):

Initialization of the storage driver.

This initializer adds a new parameter write_delay to the initialization of TinyDB's JSONStorage base class.

Parameters
path:strWhere to store the JSON data.
create_dirs:boolWhether the directory structure to the database file should be created or not.
encoding:strThe encoding character set for the database file
access_mode:strMode in which the file is opened.
write_delay:intTime to wait before writing a changed database buffer, in seconds.
**kwargs:AnyAny other argument.
def close(self):

Write any dirty database files and close all handles.

def read(self) -> dict[str, dict[str, Any]] | None:

Read the current state.

This just returns the in-memory representation of the database.

Returns
dict[str, dict[str, Any]] | NoneReturn the current state.
def write(self, data: dict[str, dict[str, Any]]):

Write the current state of the database to the storage.

This is not done directly, but it is indicated that the data has changed and should be written during the next phase of the buffered write.

Parameters
data:dict[str, dict[str, Any]]The current state of the database.
__slots__: tuple[str, ...] =

Define slots for instance variables.

def _fileWriter(self):

Worker for the file writer thread.

_changed: bool =

Indicator that the write buffer is dirty and needs to be written.

_data: dict[str, dict[str, Any]] =

The actual database data, which is also strored in memory as a buffer.

_running: bool =

Indicating that the database is open and in use.

_shutdownLock =

Internal lock when shutting down the database.

_shutting_down: bool =

Indicator that the database is closing. This is different from _running.

_writeDelay: int =

Time to wait before writing a changed database buffer, in seconds.

_writeEvent =

Event instance to notify when a write happened.