def create_edge(self, outV, label, inV, data=None): """ Creates a edge and returns the Response. :param outV: Outgoing vertex ID. :type outV: int :param label: Edge label. :type label: str :param inV: Incoming vertex ID. :type inV: int :param data: Property data. :type data: dict or None :rtype: Neo4jResponse """ if self.config.autoindex is True: index_name = self.config.edge_index return self.create_indexed_edge(outV, label, inV, data, index_name, keys=None) data = self._remove_null_values(data) inV_uri = self._build_vertex_uri(inV) path = build_path(vertex_path, outV, "relationships") params = {"to": inV_uri, "type": label, "data": data} return self.request.post(path, params)
def update_vertex(self,_id,data): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.vertex_autoindex return self.update_indexed_vertex(_id,data,index_name,keys=None) path = build_path(self.vertex_path,_id,"properties") return self.request.put(path,data)
def create_unique_vertex(self, index_name, key, value, data=None): """ Create unique (based on the key / value pair) vertex with the properties described by data. :param index_name: Name of the index. :type index_name: str :param key: Name of the key. :type key: str :param value: Value of the key. :type value: str :param data: Properties of the new element. :type data: dict :rtype: Neo4jResponse """ data = {} if data is None else data data = self._remove_null_values(data) path = (build_path(index_path, vertex_path, index_name) + '?uniqueness=get_or_create') params = {'key': key, 'value': value, 'properties': data} return self.request.post(path, params)
def put_vertex(self, index_name, key, value, _id): """ Adds a vertex to the index with the index_name. :param index_name: Name of the index. :type index_name: str :param key: Name of the key. :type key: str :param value: Value of the key. :type value: str :param _id: Vertex ID :type _id: int :rtype: RexsterResponse """ # Rexster's API only supports string lookups so convert value to a string path = build_path(index_path, index_name) params = { 'key': key, 'value': str(value), 'class': 'vertex', 'id': _id } return self.request.put(path, params)
def update_edge(self,_id,data): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.edge_autoindex return self.update_indexed_edge(_id,data,index_name,keys=None) path = build_path("relationship",_id,"properties") return self.request.put(path,data)
def update_edge(self, _id, data): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.edge_autoindex return self.update_indexed_edge(_id, data, index_name, keys=None) path = build_path("relationship", _id, "properties") return self.request.put(path, data)
def update_vertex(self, _id, data): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.vertex_autoindex return self.update_indexed_vertex(_id, data, index_name, keys=None) path = build_path(self.vertex_path, _id, "properties") return self.request.put(path, data)
def create_edge(self, outV, label, inV, data=None, keys=None): """ Creates a edge and returns the Response. :param outV: Outgoing vertex ID. :type outV: int :param label: Edge label. :type label: str :param inV: Incoming vertex ID. :type inV: int :param data: Property data. :type data: dict or None :rtype: Neo4jResponse """ if keys or self.config.autoindex is True: index_name = self.config.edge_index return self.create_indexed_edge(outV, label, inV, data, index_name, keys=keys) data = self._remove_null_values(data) inV_uri = self._build_vertex_uri(inV) path = build_path(vertex_path, outV, "relationships") params = {'to': inV_uri, 'type': label, 'data': data} return self.request.post(path, params)
def create_edge(self,outV,label,inV,data={}): """Creates a edge and returns the Response.""" data = self._remove_null_values(data) inV_uri = self._build_vertex_uri(inV) path = build_path(vertex_path,outV,"relationships") params = {'to':inV_uri,'type':label, 'data':data} return POST, path, params
def create_edge_index(self,name,*args,**kwds): path = build_path(self.index_path,name) index_type = kwds.get('index_type','automatic') index_keys = kwds.get('index_keys',None) params = {'class':'edge','type':index_type} if index_keys: params.update({'keys':index_keys}) return self.request.post(path,params)
def create_edge_index(self, name, *args, **kwds): path = build_path(self.index_path, name) index_type = kwds.get('index_type', 'automatic') index_keys = kwds.get('index_keys', None) params = {'class': 'edge', 'type': index_type} if index_keys: params.update({'keys': index_keys}) return self.request.post(path, params)
def remove_vertex_from_index(self,name,_id,key=None,value=None): #if key is not None and value is not None: # path = build_path("node",name,key,value,_id) #elif key is not None: # path = build_path("node",name,key,_id) #else: # path = build_path("node",name,_id) path = build_path("node",name,key,value,_id) return self.request.delete(path,params=None)
def remove_vertex_from_index(self, name, _id, key=None, value=None): #if key is not None and value is not None: # path = build_path("node",name,key,value,_id) #elif key is not None: # path = build_path("node",name,key,_id) #else: # path = build_path("node",name,_id) path = build_path("node", name, key, value, _id) return self.request.delete(path, params=None)
def create_edge(self,outV,label,inV,data={}): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.edge_autoindex return self.create_indexed_edge(outV,label,inV,data,index_name,keys=None) path = build_path(self.vertex_path,outV,self.edge_path) inV_uri = "%s/node/%s" % (self.config.root_uri.rstrip("/"), inV) params = {'to':inV_uri,'type':label, 'data':data} return self.request.post(path,params)
def _build_vertex_uri(self, _id, *args): placeholder = self._placeholder(_id) if placeholder: return placeholder root_uri = self.config.root_uri.rstrip("/") segments = [vertex_path, _id] + list(args) path = build_path(*segments) uri = "%s/%s" % (root_uri, path) return uri
def create_edge_index(self,name,*args,**kwds): """Creates a edge index with the specified params.""" path = build_path(self.index_path,name) index_type = kwds.get('index_type','manual') index_keys = kwds.get('index_keys',None) params = {'class':'edge','type':index_type} if index_keys: params.update({'keys':index_keys}) return self.request.post(path,params)
def get_edge_indices(self): """ Returns a dict of all the vertex indices. :rtype: Neo4jResponse """ path = build_path(index_path, edge_path) params = None return self.request.get(path, params)
def _build_vertex_path(self, _id, *args): # if the _id is a placeholder, return the placeholder; # othewise, return a normal vertex path placeholder = self._placeholder(_id) if placeholder: segments = [placeholder] else: segments = [vertex_path, _id] segments = segments + list(args) return build_path(*segments)
def create_vertex_index(self, index_name, *args, **kwds): index_type = kwds.pop("index_type", "exact") provider = kwds.pop("provider", "lucene") #keys = kwds.pop("keys",None) #keys = json.dumps(keys) if keys else "null" #config = {'type':index_type,'provider':provider,'keys':str(keys)} config = {'type': index_type, 'provider': provider} path = build_path(self.index_path, "node") params = dict(name=index_name, config=config) return self.request.post(path, params)
def get_vertex_indices(self): """ Returns all the vertex indices. :rtype: Neo4jResponse """ path = build_path(index_path, "node") params = None return self.request.get(path, params)
def create_vertex_index(self,index_name,*args,**kwds): index_type = kwds.pop("index_type","exact") provider = kwds.pop("provider","lucene") #keys = kwds.pop("keys",None) #keys = json.dumps(keys) if keys else "null" #config = {'type':index_type,'provider':provider,'keys':str(keys)} config = {'type':index_type,'provider':provider} path = build_path(self.index_path,"node") params = dict(name=index_name,config=config) return self.request.post(path,params)
def put_vertex(self, name, key, value, _id): # Rexster's API only supports string lookups so convert value to a string path = build_path(self.index_path, name) params = { 'key': key, 'value': str(value), 'class': 'vertex', 'id': _id } return self.request.post(path, params)
def create_vertex_index(self,index_name,*args,**kwds): """Creates a vertex index with the specified params.""" index_type = kwds.pop("index_type","exact") provider = kwds.pop("provider","lucene") #keys = kwds.pop("keys",None) #config = {'type':index_type,'provider':provider,'keys':str(keys)} config = {'type':index_type,'provider':provider} path = build_path(index_path,"node") params = dict(name=index_name,config=config) return POST, path, params
def bothV_ids(self, _id, label=None, start=None, limit=None, properties=None): path = build_path(vertex_path, _id, "bothIds") params = build_params(_label=label, _limit=limit, _properties=properties) return self.request.get(path, params)
def inV_count(self, _id, label=None, start=None, limit=None, properties=None): path = build_path(vertex_path, _id, "inCount") params = build_params(_label=label, _limit=limit, _properties=properties) return self.request.get(path, params)
def get_vertex(self, _id): """ Gets the vertex with the _id and returns the Response. :param data: Vertex ID. :type data: int :rtype: RexsterResponse """ path = build_path(vertex_path, _id) return self.request.get(path, params=None)
def get_edge(self, _id): """ Gets the edge with the _id and returns the Response. :param data: Edge ID. :type data: int :rtype: RexsterResponse """ path = build_path(edge_path, _id) return self.request.get(path, params=None)
def delete_edge(self, _id): """ Deletes a edge with the _id and returns the Response. :param _id: Edge ID. :type _id: dict :rtype: RexsterResponse """ path = build_path(edge_path, _id) return self.request.delete(path, params=None)
def delete_vertex(self, _id): """ Deletes a vertex with the _id and returns the Response. :param _id: Vertex ID. :type _id: dict :rtype: RexsterResponse """ path = build_path(vertex_path, _id) return self.request.delete(path, params=None)
def delete_edge_index(self, index_name): """ Deletes the edge index with the index_name. :param index_name: Name of the index. :type index_name: str :rtype: Neo4jResponse """ path = build_path(index_path, edge_path, index_name) params = None return self.request.delete(path, params)
def test_post(self): name_in = "james" email_in = "*****@*****.**" path = build_path("vertices") params = dict(name=name_in, email=email_in) resp = self.request.post(path,params) assert resp.results._type == 'vertex' assert name_in == resp.results.get('name') assert email_in == resp.results.get('email') # use the results of this function for get and delete tests return resp
def test_post(self): name_in = "james" email_in = "*****@*****.**" path = build_path("vertices") params = dict(name=name_in, email=email_in) resp = self.request.post(path, params) assert resp.results._type == 'vertex' assert name_in == resp.results.get('name') assert email_in == resp.results.get('email') # use the results of this function for get and delete tests return resp
def create_edge(self, outV, label, inV, data={}): data = self._remove_null_values(data) if self.config.autoindex is True: index_name = self.config.edge_autoindex return self.create_indexed_edge(outV, label, inV, data, index_name, keys=None) path = build_path(self.vertex_path, outV, self.edge_path) inV_uri = "%s/node/%s" % (self.config.root_uri.rstrip("/"), inV) params = {'to': inV_uri, 'type': label, 'data': data} return self.request.post(path, params)
def test_get(self): resp1 = self.test_post() oid1 = resp1.results.get('_id') element_type1 = resp1.results.get('_type') name1 = resp1.results.get('name') email1 = resp1.results.get('email') path = build_path("vertices", oid1) params = dict(name=name1, email=email1) resp2 = self.request.get(path, params) assert oid1 == resp2.results.get('_id') assert element_type1 == resp2.results.get('_type') assert name1 == resp2.results.get('name') assert email1 == resp2.results.get('email')
def test_get(self): resp1 = self.test_post() oid1 = resp1.results.get('_id') element_type1 = resp1.results.get('_type') name1 = resp1.results.get('name') email1 = resp1.results.get('email') path = build_path("vertices",oid1) params = dict(name=name1, email=email1) resp2 = self.request.get(path,params) assert oid1 == resp2.results.get('_id') assert element_type1 == resp2.results.get('_type') assert name1 == resp2.results.get('name') assert email1 == resp2.results.get('email')
def create_edge_index(self, index_name, *args, **kwds): """ Creates a edge index with the specified params. :param index_name: Name of the index. :type index_name: str :rtype: Neo4jResponse """ path = build_path(index_path, edge_path) params = dict(name=index_name) resp = self.request.post(path, params) resp._set_index_name(index_name) return resp
def update_edge(self, _id, data, keys=None): """ Updates the edge with the _id and returns the Response. :param _id: Edge ID. :type _id: dict :param data: Property data. :type data: dict :rtype: RexsterResponse """ data = self._remove_null_values(data) path = build_path(edge_path, _id) return self.request.put(path, data)
def update_vertex(self, _id, data): """ Updates the vertex with the _id and returns the Response. :param _id: Vertex ID. :type _id: dict :param data: Property data. :type data: dict :rtype: RexsterResponse """ data = self._remove_null_values(data) path = build_path(vertex_path, _id) return self.request.put(path, data)
def query_edge(self, index_name, params): """ Queries for an edge in the index and returns the Response. :param index_name: Name of the index. :type index_name: str :param params: Query params. :type params: dict :rtype: Neo4jResponse """ path = build_path(index_path,edge_path,name) params = params return self.request.get(path, params)
def update_edge(self, _id, data): """ Updates the edge with the _id and returns the Response. :param _id: Edge ID. :type _id: dict :param data: Property data. :type data: dict :rtype: RexsterResponse """ data = self._remove_null_values(data) path = build_path(edge_path, _id) return self.request.put(path, data)
def update_vertex(self, _id, data, keys=None): """ Updates the vertex with the _id and returns the Response. :param _id: Vertex ID. :type _id: dict :param data: Property data. :type data: dict :rtype: RexsterResponse """ data = self._remove_null_values(data) path = build_path(vertex_path,_id) return self.request.put(path,data)
def query_vertex(self, index_name, params): """ Returns the vertices for the index query. :param index_name: Name of the index. :type index_name: str :param params: Query params. :type params: dict :rtype: Neo4jResponse """ path = build_path(index_path,"node",name) params = params return self.request.get(path, params)
def query_edge(self, index_name, query): """ Queries the index and returns the Response. :param index_name: Name of the index. :type index_name: str :param query: Lucene query string :type query: str :rtype: Neo4jResponse """ path = build_path(index_path, edge_path, index_name) params = dict(query=query) return self.request.get(path, params)
def create_edge_index(self, index_name, *args, **kwds): """ Creates a edge index with the specified params. :param index_name: Name of the index. :type index_name: str :rtype: Neo4jResponse """ default_config = {"type": "exact", "provider": "lucene"} index_config = kwds.pop("index_config", default_config) path = build_path(index_path, edge_path) params = dict(name=index_name, config=index_config) resp = self.request.post(path, params) resp._set_index_name(index_name) return resp
def create_edge_index(self, name, *args, **kwds): """ Creates a edge index with the specified params. :param index_name: Name of the index. :type index_name: str :rtype: RexsterResponse """ path = build_path(index_path, name) index_type = kwds.get('index_type', 'manual') index_keys = kwds.get('index_keys', None) params = {'class': 'edge', 'type': index_type} if index_keys: params.update({'keys': index_keys}) return self.request.post(path, params)
def create_vertex_index(self, index_name, *args, **kwds): """ Creates a vertex index with the specified params. :param index_name: Name of the index to create. :type index_name: str :rtype: OrientDBResponse """ path = build_path(index_path, index_name) index_type = kwds.get('index_type', 'manual') index_keys = kwds.get('index_keys', None) params = {'class': 'vertex', 'type': index_type} if index_keys: params.update({'keys': index_keys}) return self.request.post(path, params)
def create_edge_index(self, index_name, *args, **kwds): """ Creates a edge index with the specified params. :param index_name: Name of the index. :type index_name: str :rtype: Neo4jResponse """ default_config = {'type': "exact", 'provider': "lucene"} index_config = kwds.pop("index_config", default_config) path = build_path(index_path, edge_path) params = dict(name=index_name, config=index_config) resp = self.request.post(path, params) resp._set_index_name(index_name) return resp
def create_edge_index(self, name, *args, **kwds): """ Creates a edge index with the specified params. :param index_name: Name of the index. :type index_name: str :rtype: RexsterResponse """ path = build_path(index_path, name) index_type = kwds.get("index_type", "manual") index_keys = kwds.get("index_keys", None) params = {"class": "edge", "type": index_type} if index_keys: params.update({"keys": index_keys}) return self.request.post(path, params)
def lookup_vertex(self, index_index_name, key, value): """ Returns the vertices indexed with the key and value. :param index_name: Name of the index. :type index_name: str :param key: Name of the key. :type key: str :param value: Value of the key. :type value: str :rtype: RexsterResponse """ path = build_path(index_path, index_index_name) params = dict(key=key, value=value) return self.request.get(path, params)
def lookup_edge(self, index_index_name, key, value): """ Looks up an edge in the index and returns the Response. :param index_name: Name of the index. :type index_name: str :param key: Name of the key. :type key: str :param value: Value of the key. :type value: str :rtype: RexsterResponse """ path = build_path(index_path, index_index_name) params = dict(key=key, value=value) return self.request.get(path, params)