bento_meta.object_map
This module contains ObjectMap, a class which provides the
machinery for mapping bento_meta objects to a Bento Metamodel Database
in Neo4j. Mostly not for human consumption. The ObjectMap:
interprets the attribute specification (attspec) and map specification (mapspec) associated with
Entitysubclassesprovides the
get()andput()methods to subclasses, that enable them to get and put themselves to the databasegenerates appropriate
Cypher <https://neo4j.com/docs/cypher-manual/current/> queries to do gets and puts One ObjectMap instance should be generated for each Entity subclass (see, e.g.,
bento_meta.model.Model)
Classes
Machinery for mapping bento_meta objects to a Bento Metamodel Database in Neo4j. |
Module Contents
- class bento_meta.object_map.ObjectMap(*, cls: type[bento_meta.entity.Entity] | None = None, drv: neo4j.Driver | None = None)[source]
Machinery for mapping bento_meta objects to a Bento Metamodel Database in Neo4j.
Mostly not for human consumption.
- cache: ClassVar[dict]
- cls = None
- maps
- classmethod cls_by_label(lbl: str) type[bento_meta.entity.Entity] | None[source]
Get the class by label.
- classmethod keys_by_cls_and_reln(qcls: type[bento_meta.entity.Entity], reln: str) tuple[str, str | None] | None[source]
Get the keys by class and relationship.
- classmethod _quote_val(value: str | float | None, *, single: bool | None = None) str | float | None[source]
Quote the value unless single is set.
- get_by_id(obj: bento_meta.entity.Entity, id: str, *, refresh: bool = False) bento_meta.entity.Entity | None[source]
Get an entity given an id attribute value (not the Neo4j id).
- get_by_node_nanoid(obj: bento_meta.entity.Entity, nanoid: str, *, refresh: bool = False) bento_meta.entity.Entity | None[source]
PROTOTYPE: Get an entity given an id attribute value (not the Neo4j id).
- get(obj: bento_meta.entity.Entity, *, refresh: bool = False) bento_meta.entity.Entity[source]
Get the data for an object instance from the db and load the instance with it.
- put(obj: bento_meta.entity.Entity) bento_meta.entity.Entity[source]
Put the object instance’s attributes to the mapped data node in the database.
- rm(obj: bento_meta.entity.Entity, *, force: bool | int = False) Any | None[source]
‘Delete’ the object’s mapped node from the database.
- add(obj: bento_meta.entity.Entity, att: str, tgt: bento_meta.entity.Entity) Any[source]
Create a link between an object instance and a target object in the database.
This represents adding an object-valued attribute to the object.
- Parameters:
obj – The object instance to add attribute to.
att – The attribute name.
tgt – The target entity to link.
- Returns:
The Neo4j ID of the target, or None if not found.
- drop(obj: bento_meta.entity.Entity, att: str, tgt: bento_meta.entity.Entity, tx: neo4j.Transaction | None = None) Any[source]
Remove an existing link between an object instance and a target object in the database.
This represents dropping an object-valued attribute from the object.
- Parameters:
obj – The object instance to remove attribute from.
att – The attribute name.
tgt – The target entity to unlink.
tx – Optional transaction to use for the operation.
- Returns:
The result value, or None if not found.
- get_owners(obj: bento_meta.entity.Entity) list[tuple[bento_meta.entity.Entity, tuple[str, str | None] | None]][source]
Get the nodes which are linked to the object instance (the owners of the object).
- get_q(obj: bento_meta.entity.Entity) str[source]
Get the query for an object.
- get_attr_q(obj: bento_meta.entity.Entity, att: str) str[source]
Get the query for an attribute of an object.
- get_owners_q(obj: bento_meta.entity.Entity) str[source]
Get the query for the owners of an object.
- put_q(obj: bento_meta.entity.Entity) list[str][source]
Get the query for putting an object.
- put_attr_q(obj: bento_meta.entity.Entity, att: str, values: bento_meta.entity.Entity | list[bento_meta.entity.Entity] | bento_meta.entity.CollValue) str | list[str][source]
Get the query for putting an attribute of an object.
- rm_q(obj: bento_meta.entity.Entity, *, detach: bool = False) str[source]
Get the query for removing an object.
- rm_attr_q(obj: bento_meta.entity.Entity, att: str, values: list[bento_meta.entity.Entity] | None = None) str | list[str][source]
Get the query for removing an attribute of an object.
- _check_values_list(att: str, values: list[bento_meta.entity.Entity] | bento_meta.entity.CollValue) bool[source]
Check if the values are a list of mapped Entity objects of the appropriate subclass for an attribute.