class eth.db.diff.DBDiff(changes: Dict[bytes, Union[bytes, eth.db.diff.MissingReason]] = None)

DBDiff is a read-only view of the updates/inserts and deletes generated when tracking changes with DBDiffTracker.

The primary usage is to apply these changes to your underlying database with apply_to().

apply_to(db: collections.abc.MutableMapping, apply_deletes: bool = True) → None

Apply the changes in this diff to the given database. You may choose to opt out of deleting any underlying keys.

Parameters:apply_deletes – whether the pending deletes should be applied to the database
deleted_keys() → Iterable[bytes]

List all the keys that have been deleted.

classmethod join(diffs: Iterable[DBDiff]) → eth.db.diff.DBDiff

Join several DBDiff objects into a single DBDiff object.

In case of a conflict, changes in diffs that come later in diffs will overwrite changes from earlier changes.

pending_items() → Iterable[Tuple[bytes, bytes]]

A tuple of (key, value) pairs for every key that has been updated. Like pending_keys(), this does not return any deleted keys.

pending_keys() → Iterable[bytes]

List all the keys who have had values change. This IGNORES any keys that have been deleted.


class eth.db.diff.DBDiffTracker

Records changes to a DatabaseAPI

If no value is available for a key, it could be for one of two reasons: - the key was never updated during tracking - the key was deleted at some point

When getting a value, a special subtype of KeyError is raised on failure. The exception, DiffMissingError, can be used to check if the value was deleted, or never present, using DiffMissingError.is_deleted().

When it’s time to take the tracked changes and write them to your database, get the DBDiff with DBDiffTracker.diff() and use the attached methods.


class eth.db.diff.DiffMissingError(missing_key: bytes, reason: eth.db.diff.MissingReason)

Raised when trying to access a missing key/value pair in a DBDiff or DBDiffTracker.

Use is_deleted to check if the value is missing because it was deleted, or simply because it was never updated.