DBDiff
DBDiff
- class eth.db.diff.DBDiff(changes: Dict[bytes, bytes | MissingReason] | None = 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: DatabaseAPI | 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
- classmethod join(diffs: Iterable[DBDiff]) 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.
DBDiffTracker
- 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, usingDiffMissingError.is_deleted()
.When it’s time to take the tracked changes and write them to your database, get the
DBDiff
withDBDiffTracker.diff()
and use the attached methods.
DiffMissingError
- class eth.db.diff.DiffMissingError(missing_key: bytes, reason: MissingReason)
Raised when trying to access a missing key/value pair in a
DBDiff
orDBDiffTracker
.Use
is_deleted
to check if the value is missing because it was deleted, or simply because it was never updated.