bento_meta.mdb
This module contains MDB
, with machinery for efficiently
querying a Neo4j instance of a Metamodel Database.
Subpackages
Submodules
Package Contents
Classes
Functions
|
Create a random nanoid and return it as a string. |
|
Decorates a query function to run a read transaction based on |
|
Decorates a query function to run a read transaction based on |
|
Decorates a query function to run a read transaction based on |
|
Load an MDF object into an MDB instance |
|
Load a model object into an MDB instance. |
|
Create Cypher statements from a model to load it de novo into an |
- class bento_meta.mdb.MDB(uri=os.environ.get('NEO4J_MDB_URI'), user=os.environ.get('NEO4J_MDB_USER'), password=os.environ.get('NEO4J_MDB_PASS'))[source]
- _txfns
Create an
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 theNEO4J_MDB_URI
env variable) :param str user: Username for Neo4j access (default, use theNEO4J_MDB_USER
env variable) :param str password: Password for user (default, use theNEO4J_MDB_PASS
env variable)
- register_txfn(name, fn)[source]
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.
- get_nodes_by_model(model=None)[source]
Get all nodes for a given model. If :param:model is None, get all nodes in database. Returns [ <node> ].
- get_model_nodes_edges(model)[source]
Get all node-relationship-node paths for a given model. Returns [ path ]
- get_node_edges_by_node_id(nanoid)[source]
Get incoming and outgoing relationship information for a node, given its nanoid. Returns [ {id, handle, model, near_type, far_type, rln, far_node} ].
- get_node_and_props_by_node_id(nanoid)[source]
Get a node and its properties, given the node nanoid. Returns [ {id, handle, model, node, props[]} ].
- get_nodes_and_props_by_model(model=None)[source]
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[]} ]
- get_prop_node_and_domain_by_prop_id(nanoid)[source]
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[] } ].
- get_valueset_by_id(nanoid)[source]
Get a valueset with the properties that use it and the terms that constitute it. Returns [ {id, handle, url, terms[], props[]} ]
- get_valuesets_by_model(model=None)[source]
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[]} ].
- get_term_by_id(nanoid)[source]
Get a term having the given nanoid, with its origin. Returns {term, origin}.
- get_props_and_terms_by_model(model=None)[source]
Get terms from valuesets associated with properties in a given model (or all such terms if model is None). Returns [ {prop, terms[]} ]
- get_tags_for_entity_by_id(nanoid)[source]
Get all tags attached to an entity, given the entity’s nanoid. Returns [ {model(str), tags[]} ].
- get_tags_and_values(key=None)[source]
Get all tag key/value pairs that are present in database. Returns [ { key(str) : values[] } ]
- bento_meta.mdb.make_nanoid(alphabet='abcdefghijkmnopqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789', size=6)[source]
Create a random nanoid and return it as a string.
- bento_meta.mdb.read_txn(func)[source]
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.
- bento_meta.mdb.read_txn_value(func)[source]
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.
- bento_meta.mdb.read_txn_data(func)[source]
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.
- class bento_meta.mdb.WriteableMDB(*args, **kwargs)[source]
Bases:
bento_meta.mdb.MDB
- put_term_with_origin(term, commit='', _from=1)[source]
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)
- class bento_meta.mdb.SearchableMDB(*args, **kwargs)[source]
Bases:
bento_meta.mdb.MDB
- available_indexes()[source]
Fulltext indexes present in database. Returns { <index_name> : { entity_type:<NODE|RELATIONSHIP>, entities:[<labels>], properties:[ [<props>] ] } }
- query_index(index, qstring, skip=None, limit=None)[source]
Query a named fulltext index of nodes or relationships. Returns [ {ent:{}, label:<label>, score:<lucene score>} ].
- bento_meta.mdb.load_model(model, mdb, _commit=None)[source]
Load a model object into an MDB instance.
- bento_meta.mdb.load_model_statements(model, _commit=None)[source]
Create Cypher statements from a model to load it de novo into an MDB instance.
:param
mdb.Model
model: Model instance for loading :param str _commit: ‘Commit string’ for marking entities in DB. If set, this will override _commit attributes already existing on Model entities.