Skip to content

Storage

Storage backends read and write table files. The default and only built-in backend is JsonStorage, which stores each table as human-readable JSON.

Base

base

Storage backend abstraction.

TinyStore talks to on-disk storage exclusively through :class:StorageBackend. The query engine never performs filesystem operations. Today the only backend is :class:~tinystore.storage.json.JsonStorage; the abstraction exists so that alternative backends (e.g. a single-file or memory backend for tests) can be plugged in later.

StorageBackend

Bases: ABC

Reads and writes tables, metadata, and journals.

root abstractmethod property

root: Path

Database root directory.

lock_file abstractmethod property

lock_file: Path

Path to the OS lock coordination file.

read_table abstractmethod

read_table(name: str) -> dict[str, Any]

Read a table document ({version, next_id, rows}).

Raises :class:~tinystore.exceptions.TinyStoreError if the file is missing or corrupt.

write_table abstractmethod

write_table(name: str, data: dict[str, Any]) -> None

Atomically write a table document.

JSON backend

json

JSON file storage backend.

Layout::

<root>/
  metadata.json
  tinystore.lock
  journal/<txid>.json
  tables/<name>.json

Each table is its own JSON file. Writes are atomic: data is serialized to a temporary file in the same directory, flushed and fsync'd, then os.replace'd into place, followed by a best-effort parent-directory fsync.