class documentation
class TinyDBBufferedStorage(JSONStorage):
Constructor: TinyDBBufferedStorage(path, create_dirs, encoding, access_mode, ...)
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 | _file |
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 | _shutdown |
Internal lock when shutting down the database. |
| Instance Variable | _shutting |
Indicator that the database is closing. This is different from _running. |
| Instance Variable | _write |
Time to wait before writing a changed database buffer, in seconds. |
| Instance Variable | _write |
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:str | Where to store the JSON data. |
createbool | Whether the directory structure to the database file should be created or not. |
encoding:str | The encoding character set for the database file |
accessstr | Mode in which the file is opened. |
writeint | Time to wait before writing a changed database buffer, in seconds. |
**kwargs:Any | Any other argument. |
Read the current state.
This just returns the in-memory representation of the database.
| Returns | |
dict[ | Return the current state. |
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[ | The current state of the database. |