:py:mod:`bento_meta.mdb` ======================== .. py:module:: bento_meta.mdb .. autoapi-nested-parse:: bento_meta.mdb ============== This module contains :class:`MDB`, with machinery for efficiently querying a Neo4j instance of a Metamodel Database. Subpackages ----------- .. toctree:: :titlesonly: :maxdepth: 3 mdb_tools/index.rst Submodules ---------- .. toctree:: :titlesonly: :maxdepth: 1 loaders/index.rst mdb/index.rst searchable/index.rst writeable/index.rst Package Contents ---------------- Classes ~~~~~~~ .. autoapisummary:: bento_meta.mdb.MDB bento_meta.mdb.WriteableMDB bento_meta.mdb.SearchableMDB Functions ~~~~~~~~~ .. autoapisummary:: bento_meta.mdb.make_nanoid bento_meta.mdb.read_txn bento_meta.mdb.read_txn_value bento_meta.mdb.read_txn_data bento_meta.mdb.load_mdf bento_meta.mdb.load_model bento_meta.mdb.load_model_statements .. py:class:: MDB(uri=os.environ.get('NEO4J_MDB_URI'), user=os.environ.get('NEO4J_MDB_USER'), password=os.environ.get('NEO4J_MDB_PASS')) .. py:attribute:: _txfns Create an :class:`MDB` object, with a connection to a Neo4j instance of a metamodel database. :param bolt_url uri: The Bolt protocol endpoint to the Neo4j instance (default, use the ``NEO4J_MDB_URI`` env variable) :param str user: Username for Neo4j access (default, use the ``NEO4J_MDB_USER`` env variable) :param str password: Password for user (default, use the ``NEO4J_MDB_PASS`` env variable) .. py:method:: close() .. py:method:: register_txfn(name, fn) Register a transaction function (see https://neo4j.com/docs/api/python-driver/current/api.html#managed-transactions-transaction-functions) with the class for later use. .. py:method:: get_model_handles() Return a simple list of model handles available. .. py:method:: get_model_nodes(model=None) Return a list of dicts representing Model nodes. .. py:method:: get_nodes_by_model(model=None) Get all nodes for a given model. If :param:model is None, get all nodes in database. Returns [ ]. .. py:method:: get_model_nodes_edges(model) Get all node-relationship-node paths for a given model. Returns [ path ] .. py:method:: get_node_edges_by_node_id(nanoid) Get incoming and outgoing relationship information for a node, given its nanoid. Returns [ {id, handle, model, near_type, far_type, rln, far_node} ]. .. py:method:: get_node_and_props_by_node_id(nanoid) Get a node and its properties, given the node nanoid. Returns [ {id, handle, model, node, props[]} ]. .. py:method:: get_nodes_and_props_by_model(model=None) Get all nodes with associated properties given a model handle. If model is None, get all nodes with their properties. Returns [ {id, handle, model, props[]} ] .. py:method:: get_prop_node_and_domain_by_prop_id(nanoid) Get a property, its node, and its value domain or value set of terms, given the property nanoid. Returns [ { id, handle, model, value_domain, prop, node, value_set, terms[] } ]. .. py:method:: get_valueset_by_id(nanoid) Get a valueset with the properties that use it and the terms that constitute it. Returns [ {id, handle, url, terms[], props[]} ] .. py:method:: get_valuesets_by_model(model=None) Get all valuesets that are used by properties in the given model (or all valuesets if model is None). Also return list of properties using each valueset. Returns [ {value_set, props[]} ]. .. py:method:: get_term_by_id(nanoid) Get a term having the given nanoid, with its origin. Returns {term, origin}. .. py:method:: get_props_and_terms_by_model(model=None) Get terms from valuesets associated with properties in a given model (or all such terms if model is None). Returns [ {prop, terms[]} ] .. py:method:: get_origins() Get all origins. Returns [ ] .. py:method:: get_origin_by_id(oid) Get an origin by nanoid. .. py:method:: get_tags_for_entity_by_id(nanoid) Get all tags attached to an entity, given the entity's nanoid. Returns [ {model(str), tags[]} ]. .. py:method:: get_tags_and_values(key=None) Get all tag key/value pairs that are present in database. Returns [ { key(str) : values[] } ] .. py:method:: get_entities_by_tag(key, value=None, model=None) Get all entities, optionally from a given model, tagged with a given key or key:value pair. Returns [ {tag_key(str), tag_value(str), entity(str - label), entities[]} ] .. py:method:: get_with_statement(qry, parms={}) Run an arbitrary read statement and return data. .. py:function:: make_nanoid(alphabet='abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789', size=6) Create a random nanoid and return it as a string. .. py:function:: read_txn(func) Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict). Returns list of driver Records. .. py:function:: read_txn_value(func) Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict, values_key). Returns list of values for key specified by query function. .. py:function:: read_txn_data(func) Decorates a query function to run a read transaction based on its query. Query function should return a tuple (qry_string, param_dict). Returns records as a list of simple dicts. .. py:class:: WriteableMDB(*args, **kwargs) Bases: :py:obj:`bento_meta.mdb.MDB` .. py:method:: put_with_statement(qry, parms={}) Run an arbitrary write statement. .. py:method:: put_term_with_origin(term, commit='', _from=1) Merge a bento-meta Term object, that has an Origin object set, into an MDB. If a new term is created, assign a random 6-char nanoid to it. The Origin must already be represented in the database. :param Term term: Term object :param str commit: GitHub commit SHA1 associated with the term (if any) .. py:class:: SearchableMDB(*args, **kwargs) Bases: :py:obj:`bento_meta.mdb.MDB` .. py:method:: available_indexes() Fulltext indexes present in database. Returns { : { entity_type:, entities:[], properties:[ [] ] } } .. py:method:: query_index(index, qstring, skip=None, limit=None) Query a named fulltext index of nodes or relationships. Returns [ {ent:{}, label: