def _create_constraint(graph, constraint_type, label, property_key): """Create a uniqueness constraint.""" tpl = _schema_template(graph, 'constraints', label=label, property_key=False, constraint_type=constraint_type) resource = Resource(tpl.expand(label=label, property_key=property_key)) resource.post({"property_keys": [property_key]})
def schema_indexes(graph): # type: (Graph) -> List[Tuple[str, List[str]]] """Query iterable list of *all* schema indexes. This works around the fact that, in Neo4j 2.3 and :mod:`py2neo` 2.0.8 at least, `graph.node_labels` only returns labels used by extant nodes, whereas previously it returned all labels, which are needed for clearing the constrain schema by iterating over the labels. """ index_resource = Resource(graph_metadata(graph, 'indexes')) return [(n['label'], n['property_keys']) for n in index_resource.get().content]
def schema_constraints(graph): # type: (Graph) -> Iterable[Tuple[str, List[str], str]] """Query iterable list of *all* schema constraints. This works around the fact that, in Neo4j 2.3 and :mod:`py2neo` 2.0.8 at least, `graph.node_labels` only returns labels used by extant nodes, whereas previously it returned all labels, which are needed for clearing the constrain schema by iterating over the labels. """ resource_type = type(Resource) constraint_resource = Resource(graph_metadata(graph, 'constraints')) return ((c['label'], c['property_keys'], c['type']) for c in constraint_resource.get().content)
def resolve(self, reference, strict=True): """ Resolve a URI reference against the URI for this resource, returning a new resource represented by the new target URI. :arg reference: Relative URI to resolve. :arg strict: Strict mode flag. :rtype: :class:`.Resource` """ return Resource(_Resource.resolve(self, reference, strict).uri)
def _drop_constraint(graph, constraint_type, label, property_key): # type: (Graph, str, str) -> None key_template = _schema_template(graph, schema_type='constraints', constraint_type=constraint_type, label=label, property_key=property_key) url_expanded = key_template.expand(label=label, property_key=property_key) resource = Resource(url_expanded) try: resource.delete() except Exception: log.exception('error deleting constraint' ' type="%s" label="%s" property="%s"', constraint_type, label, property_key) raise
def __init__(self, uri, metadata=None, headers=None): uri = URI(uri) self._resource = _Resource.__init__(self, uri) self._headers = dict(headers or {}) self.__base = super(Resource, self) if metadata is None: self.__initial_metadata = None else: self.__initial_metadata = dict(metadata) self.__last_get_response = None uri = uri.string dbms_uri = uri[:uri.find("/", uri.find("//") + 2)] + "/" if dbms_uri == uri: self.__dbms = self else: from py2neo.database import DBMS self.__dbms = DBMS(dbms_uri) self.__ref = NotImplemented