ApdbMetadata

class lsst.dax.apdb.ApdbMetadata

Bases: ABC

Interface for accessing APDB metadata.

Metadata is a collection of key/value items usually stored in a special table in the database. This abstract interface provides methods for accessing and modifying it.

Methods Summary

delete(key)

Delete metadata record.

empty()

Check whether attributes set is empty.

get(key[, default])

Retrieve value of a given metadata record.

items()

Iterate over records and yield their keys and values.

set(key, value, *[, force])

Set value for a given metadata record.

Methods Documentation

abstract delete(key: str) bool

Delete metadata record.

Parameters:
keystr

Metadata key, arbitrary non-empty string.

Returns:
existedbool

True is returned if attribute existed before it was deleted.

abstract empty() bool

Check whether attributes set is empty.

Returns:
emptybool

True if there are no any attributes defined. True is also returned if metadata table is missing.

abstract get(key: str, default: str | None = None) str | None

Retrieve value of a given metadata record.

Parameters:
keystr

Metadata key, arbitrary non-empty string.

defaultstr, optional

Default value returned when key does not exist, can be string or None.

Returns:
valuestr or None

Metadata value, if key does not exist then default is returned.

abstract items() Generator[tuple[str, str], None, None]

Iterate over records and yield their keys and values.

Yields:
keystr

Metadata key.

valuestr

Corresponding metadata value.

abstract set(key: str, value: str, *, force: bool = False) None

Set value for a given metadata record.

Parameters:
keystr

Metadata key, arbitrary non-empty string.

valuestr

New metadata value, an arbitrary string. Due to deficiencies of some database engines we are not allowing empty strings to be stored in the database, and value cannot be an empty string.

forcebool, optional

Controls handling of existing metadata. With default False value an exception is raised if key already exists, if True is passed then value of the existing key will be updated.

Raises:
KeyError

Raised if key already exists but force option is false.

ValueError

Raised if key or value parameters are empty.