Ejemplo n.º 1
0
 def create(self,*args,**kwds):
     relationship = instantiate_model(self.element_class,self.resource,kwds)
     outV, label, inV = self._parse_args(relationship,args)
     data = relationship._get_property_data()
     resp = relationship._create(outV,label,inV,data)
     result = get_one_result(resp)
     return initialize_element(self.resource,result)
Ejemplo n.º 2
0
Archivo: index.py Proyecto: Hinge/bulbs
    def create_unique_vertex(self, key=None, value=None, data=None, **pair):
        """
        Returns a tuple containing two values. The first is the element if it
        was created / found. The second is a boolean value the tells whether
        the element was created (True) or not (False).

        :param key: The index key.
        :type key: str

        :param value: The key's value.
        :type value: str or int

        :param pair: Optional key/value pair. Example: name="James"
        :type pair: key/value pair

        :rtype: tuple

        """
        key, value = self._get_key_value(key,value,pair)
        data = {} if data is None else data
        create = self._get_method(vertex="create_unique_vertex")
        resp = create(self.index_name, key, value, data)
        if resp.total_size > 0:
            result = get_one_result(resp)
            was_created = resp.headers['status'] == '201'
            return initialize_element(self.client, result), was_created
        else:
            return None, False
Ejemplo n.º 3
0
    def create_unique_vertex(self, key=None, value=None, data=None, **pair):
        """
        Returns a tuple containing two values. The first is the element if it
        was created / found. The second is a boolean value the tells whether
        the element was created (True) or not (False).

        :param key: The index key.
        :type key: str

        :param value: The key's value.
        :type value: str or int

        :param pair: Optional key/value pair. Example: name="James"
        :type pair: key/value pair

        :rtype: tuple

        """
        key, value = self._get_key_value(key, value, pair)
        data = {} if data is None else data
        create = self._get_method(vertex="create_unique_vertex")
        resp = create(self.index_name, key, value, data)
        if resp.total_size > 0:
            result = get_one_result(resp)
            was_created = resp.headers['status'] == '201'
            return initialize_element(self.client, result), was_created
        else:
            return None, False
Ejemplo n.º 4
0
 def update(self, _id, *args, **kwds):
     relationship = instantiate_model(self.element_class, self.resource,
                                      kwds)
     data = relationship._get_property_data()
     resp = relationship._update(_id, data)
     result = get_one_result(resp)
     return initialize_element(self.resource, result)
Ejemplo n.º 5
0
 def update(self, _id, *args, **kwds):
     node = instantiate_model(self.element_class, self.resource, kwds)
     data = node._get_property_data()
     resp = node._update(_id, data, self.index)
     result = get_one_result(resp)
     # TODO: make this work for neo4j b/c neo4j doesn't return data
     return initialize_element(self.resource, result)
Ejemplo n.º 6
0
 def create(self,*args,**kwds):
     node = instantiate_model(self.element_class,self.resource,kwds)
     data = node._get_property_data()
     resp = node._create(data,self.index)
     result = get_one_result(resp)  
     # doing it this way you're losing any extra kwds that may have been set
     return initialize_element(self.resource,result)
Ejemplo n.º 7
0
 def update(self,_id,*args,**kwds):
     node = instantiate_model(self.element_class,self.resource,kwds)
     data = node._get_property_data()
     resp = node._update(_id,data,self.index)
     result = get_one_result(resp)
     # TODO: make this work for neo4j b/c neo4j doesn't return data
     return initialize_element(self.resource,result)
Ejemplo n.º 8
0
 def get_unique(self, key=None, value=None, **pair):
     """Returns a max of 1 elements matching the key/value pair in the index."""
     key, value = self._get_key_value(key,value,pair)
     lookup = self._get_method(vertex="lookup_vertex", edge="lookup_edge")
     resp = lookup(self.index_name,key,value)
     if resp.total_size > 0:
         result = get_one_result(resp)
         return initialize_element(self.client,result)
Ejemplo n.º 9
0
 def create(self,*args,**kwds):
     import pdb; pdb.set_trace()
     node = instantiate_model(self.element_class,self.resource,kwds)
     data = node._get_property_data()
     resp = node._create(data,self.index)
     # see comments in utils.get_one_result for why we're using this
     result = get_one_result(resp)  
     # doing it this way you're losing any extra kwds that may have been set
     return initialize_element(self.resource,result)
Ejemplo n.º 10
0
 def create(self, *args, **kwds):
     import pdb
     pdb.set_trace()
     node = instantiate_model(self.element_class, self.resource, kwds)
     data = node._get_property_data()
     resp = node._create(data, self.index)
     # see comments in utils.get_one_result for why we're using this
     result = get_one_result(resp)
     # doing it this way you're losing any extra kwds that may have been set
     return initialize_element(self.resource, result)
Ejemplo n.º 11
0
 def create(self, *args, **kwds):
     relationship = instantiate_model(self.element_class, self.resource,
                                      kwds)
     outV, label, inV = self._parse_args(relationship, args)
     data = relationship._get_property_data()
     log.debug("DATA: %s", data)
     resp = relationship._create(outV, label, inV, data)
     log.debug("RESP: %s", resp.raw)
     result = get_one_result(resp)
     return initialize_element(self.resource, result)
Ejemplo n.º 12
0
    def get_unique(self, key=None, value=None, **pair):
        """
        Returns a max of 1 elements matching the key/value pair in the index.

        :param key: The index key. This is optional because you can instead 
                    supply a key/value pair such as name="James". 

        :param value: The index key's value. This is optional because you can 
                      instead supply a key/value pair such as name="James". 

        :param **pair: Optional keyword param. Instead of supplying key=name 
                       and value = 'James', you can supply a key/value pair in
                       the form of name='James'.
        """
        key, value = self._parse_args(key, value, pair)
        resp = self.resource.lookup_vertex(self.index_name, key, value)
        result = get_one_result(resp)
        return initialize_element(self.resource, result)
Ejemplo n.º 13
0
    def get_unique(self,key=None,value=None,**pair):
        """
        Returns a max of 1 elements matching the key/value pair in the index.

        :param key: The index key. This is optional because you can instead 
                    supply a key/value pair such as name="James". 

        :param value: The index key's value. This is optional because you can 
                      instead supply a key/value pair such as name="James". 

        :param **pair: Optional keyword param. Instead of supplying key=name 
                       and value = 'James', you can supply a key/value pair in
                       the form of name='James'.
        """
        key, value = self._parse_args(key,value,pair)
        resp = self.resource.lookup_vertex(self.index_name,key,value)
        result = get_one_result(resp)
        return initialize_element(self.resource,result)
Ejemplo n.º 14
0
Archivo: index.py Proyecto: kod3r/bulbs
    def get_unique(self, key=None, value=None, **pair):
        """
        Returns a max of 1 elements in the index matching the key/value pair.

        :param key: The index key. 
        :type key: str

        :param value: The key's value.
        :type value: str or int

        :param pair: Optional key/value pair. Example: name="James"
        :type pair: key/value pair

        :rtype: Element or None

        """
        key, value = self._get_key_value(key, value, pair)
        lookup = self._get_method(vertex="lookup_vertex", edge="lookup_edge")
        resp = lookup(self.index_name, key, value)
        if resp.total_size > 0:
            result = get_one_result(resp)
            return initialize_element(self.client, result)
Ejemplo n.º 15
0
    def get_unique(self, key=None, value=None, **pair):
        """
        Returns a max of 1 elements in the index matching the key/value pair.

        :param key: The index key. 
        :type key: str

        :param value: The key's value.
        :type value: str or int

        :param pair: Optional key/value pair. Example: name="James"
        :type pair: key/value pair

        :rtype: Element or None

        """
        key, value = self._get_key_value(key,value,pair)
        lookup = self._get_method(vertex="lookup_vertex", edge="lookup_edge")
        resp = lookup(self.index_name,key,value)
        if resp.total_size > 0:
            result = get_one_result(resp)
            return initialize_element(self.client,result)
Ejemplo n.º 16
0
 def count(self, key, value):
     script = self.resource.scripts.get('index_count')
     params = dict(index_name=self.index_name, key=key, value=value)
     resp = self.resource.gremlin(script, params)
     return get_one_result(resp)
Ejemplo n.º 17
0
 def get_unique(self,key=None,value=None,**pair):
     """Returns a max of 1 elements matching the key/value pair in the index."""
     key, value = self._get_key_value(key,value,pair)
     resp = self.resource.lookup_vertex(self.index_name,key,value)
     result = get_one_result(resp)
     return initialize_element(self.resource,result)
Ejemplo n.º 18
0
 def update(self,_id,*args,**kwds):
     relationship = instantiate_model(self.element_class,self.resource,kwds)
     data = relationship._get_property_data()
     resp = relationship._update(_id,data)
     result = get_one_result(resp)
     return initialize_element(self.resource,result)
Ejemplo n.º 19
0
 def update(self,_id,*args,**kwds):
     node = instantiate_model(self.element_class,self.resource,kwds)
     data = node._get_property_data()
     resp = node._update(_id,data,self.index)
     result = get_one_result(resp)
     return initialize_element(self.resource,result)
Ejemplo n.º 20
0
 def lookup_unique(self, key=None, value=None, **pair):
     """Returns a max of 1 elements matching the key/value pair in the index."""
     key, value = self._parse_args(key, value, pair)
     resp = self.resource.lookup_vertex(self.index_name, key, value)
     result = get_one_result(resp)
     return initialize_element(self.resource, result)
Ejemplo n.º 21
0
 def count(self,key,value):
     script = self.resource.scripts.get('index_count')
     params = dict(index_name=self.index_name,key=key,value=value)
     resp = self.resource.gremlin(script,params)
     return get_one_result(resp)