bento_meta.entity ================= .. py:module:: bento_meta.entity .. autoapi-nested-parse:: bento_meta.entity ================= This module contains * `Entity`, the base class for metamodel objects, * the `CollValue` class to manage collection-valued attributes, and * the `ArgError` exception. Exceptions ---------- .. autoapisummary:: bento_meta.entity.ArgError Classes ------- .. autoapisummary:: bento_meta.entity.Entity bento_meta.entity.CollValue Module Contents --------------- .. py:exception:: ArgError Bases: :py:obj:`Exception` Exception for method argument errors. .. py:class:: Entity(init: dict | neo4j.graph.Node | Entity | None = None) Base class for all metamodel objects. Entity contains all the magic for metamodel objects such as `bento_meta.objects.Node` and 'bento_meta.object.Edge`. It will rarely be used directly. Entity redefines `__setattr__` and `__getattr__` to enable graph database object mapping under the hood. The Entity class also defines private and declared attributes that are common to all metamodel objects. It provides the machinery to manage private attributes separately from declared attributes, and to raise exceptions when attempts are made to access attributes that are not declared. .. py:attribute:: pvt_attr :type: ClassVar[list[str]] :value: ['pvt', 'neoid', 'dirty', 'removed_entities', 'attspec', 'mapspec', 'belongs'] .. py:attribute:: defaults .. py:attribute:: attspec_ :type: ClassVar[dict[str, str]] .. py:attribute:: attspec .. py:attribute:: mapspec_ :type: ClassVar[dict[str, str | dict[str, str] | dict[str, dict[str, str | set[str]]] | None]] .. py:property:: object_map :type: bento_meta.object_map.ObjectMap | None Return object map. .. py:attribute:: pvt .. py:attribute:: neoid :value: None .. py:property:: dirty :type: int Flag whether this instance has been changed since retrieval from the database. Set to -1, ensure that the next time an attribute is accessed, the instance will retrieve itself from the database. .. py:property:: removed_entities :type: list[Any] Return list of removed entities. .. py:property:: belongs :type: dict[tuple[int, str, str] | tuple[int, str], Entity] Return dict that stores information on the owners (referents) of this instance in the model. .. py:method:: mapspec() -> dict[str, str | dict[str, str]] :classmethod: Get object to database mapping specification. Is a class method, not a property. .. py:method:: default(propname: str) -> Any :classmethod: Return a default value for the property named. :param propname: Name of the property to get default for. :returns: Default value if defined, None otherwise. .. py:method:: get_by_id(id: str) -> Entity | None Get an object from the db with the id attribute (not the Neo4j id). :param id: Value of id for desired object. :returns: A new object if found, None otherwise. .. py:method:: clear_removed_entities() -> None Clear the list of removed entities. .. py:method:: set_with_dict(init: dict) -> None Set the entity with a dict. .. py:method:: set_with_node(init: neo4j.graph.Node) -> None Set the entity with a Neo4j node. .. py:method:: set_with_entity(ent: Entity) -> Entity Set the entity with another entity. .. py:method:: __getattribute__(name: str) -> Any Get the attribute of the entity. .. py:method:: __getattr__(name: str) -> Any Get the attribute of the entity. .. py:method:: __setattr__(name: str, value: Any) -> None Set the attribute of the entity. .. py:method:: _set_declared_attr(name: str, value: Any) -> None Set the declared attribute of the entity. .. py:method:: __delattr__(name: str) -> None Delete the attribute of the entity. .. py:method:: _check_init(init: dict) -> None Check the initial value of the entity. .. py:method:: _check_value(att: str, value: Any) -> None Check the value of the attribute. .. py:method:: dup() -> Entity Duplicate the object, but not too deeply. .. py:method:: delete() -> None Delete self from the database. .. py:method:: dget(*, refresh: bool = False) -> Entity | None Update self from the database. :param refresh: If True, force a retrieval from db. If False, retrieve from cache and don't disrupt changes already made. :returns: The entity if found, None otherwise. .. py:method:: dput() -> None Put self to the database. This will set the neoid property if not yet set. .. py:method:: rm(*, force: bool = False) -> None Delete self from the database. The object instance survives. :param force: If True, detach and delete the node. .. py:method:: attr_doc() -> str :classmethod: Create a docstring for declared attributes on class as configured. .. py:method:: get_label() -> str | dict[str, str] | dict[str, dict[str, str | set[str]]] | None Return type of entity as label. .. py:method:: get_attr_dict() -> dict[str, str] Return simple attributes set for Entity as a dict. Attr values are converted to strings. Doesn't include attrs with None values. :returns: Dictionary of attribute names to string values. .. py:class:: CollValue(init: dict | None = None, *, owner: Entity, owner_key: str) Bases: :py:obj:`collections.UserDict` A UserDict for housing Entity collection attributes. This class contains a hook for recording the Entity that owns the value that is being set. The value is marked as belonging to the containing object, not this collection object. It also protects against adding arbitrarily typed elements to the collection; it throws unless a value to set is an Entity. .. attribute:: owner Entity object of which this collection is an attribute. .. attribute:: owner_key The attribute name of this collection on the owner. .. py:property:: owner :type: Entity The entity instance of which this collection is an attribute. .. py:property:: owner_key :type: str The attribute name of this collection on the `owner`. .. py:method:: __setitem__(name: str, value: Entity) -> None Set the value for the collection. .. py:method:: __getitem__(name: str) -> Any Get the value for the collection. .. py:method:: __delitem__(name: str) -> None Delete the value for the collection.