Skip to content

database

Classes:

  • DatabaseStorage

    Stores data directly in the database instead of remotely.

Attributes:

database_storage module-attribute

database_storage = DatabaseStorage()

A singleton instance of DatabaseStorage for convenience.

DatabaseStorage

DatabaseStorage(
    *,
    warn_size: int = WARN_SIZE_DEFAULT,
    error_size: int = ERROR_SIZE_DEFAULT
)

Bases: Storage[str]

Stores data directly in the database instead of remotely.

Is constrained to:

  • JSON content types (e.g., application/json, application/vnd.api+json)
  • No data streams, only single JSON strings
  • A maximum size. By default it warns at 10 KB and raises an error at 100 KB.

Is most useful in cases where

Methods:

deserialize_config

deserialize_config(data: str) -> str

Return the data as-is because it is already a JSON string.

read_data async

read_data(config: str) -> bytes

Load data using the given information.

read_data_stream

read_data_stream(config: str) -> AsyncGenerator[bytes]

Load a stream of data using the given information.

serialize_config

serialize_config(config: str) -> str

Return the config as-is because it is already a JSON string.

write_data async

write_data(
    data: bytes, digest: Digest, _tags: TagMap
) -> str

Save the given value data.

write_data_stream async

write_data_stream(
    data_stream, get_digest, _tags: TagMap
) -> str

Save the given data stream.