コード例 #1
0
    def build(self):
        save_query = self.query.queries[0]
        edge = GetEdge(self.out_v_id, self.in_v_id, self.label,
                       self.mapper.unique)
        gremlin = self.gremlin

        gremlin.apply_statement(edge)
        gremlin.tryNext().orElseGet.close(save_query['script'])
コード例 #2
0
    def _remove(self, entity, direction='both'):
        """method used to remove a connection between vertices. This method
        does not execute the query, but will enqueue it with the mapper"""
        from gremlinpy.statement import GetEdge

        try:
            edge = GetEdge(entity['id'],
                           self._entity['id'],
                           label=str(self._edge_entity),
                           direction=direction)
            self.mapper.delete(edge)

            return edge
        except:
            return None
コード例 #3
0
ファイル: mapper.py プロジェクト: sns/Gizmo
    def _save_edge(self, model, bind_return=True):
        query = Query(self.gremlin, self.mapper)
        save = True
        import pudb
        pu.db

        out_v = model.out_v
        in_v = model.in_v
        import pudb
        pu.db
        out_v_ref = self.mapper.get_model_variable(out_v)
        in_v_ref = self.mapper.get_model_variable(in_v)

        if not out_v_ref and isinstance(out_v,
                                        Vertex) and out_v['_id'] is None:
            self.mapper.save(out_v)
            out_v = self.mapper.get_model_variable(out_v)
        else:
            out_v = out_v_ref

        if not in_v_ref and isinstance(in_v, Vertex) and in_v['_id'] is None:
            self.mapper.save(in_v)
            in_v = self.mapper.get_model_variable(in_v)
        else:
            in_v = in_v_ref

        out_v = out_v['_id'] if isinstance(out_v, Vertex) else out_v
        in_v = in_v['_id'] if isinstance(in_v, Vertex) else in_v

        if model['_id'] and self.unique:
            edge = GetEdge(out_v, in_v, model['_label'])
            gremlin = Gremlin(self.gremlin.gv)

            gremlin.apply_statement(edge)

            try:
                edge = self.mapper.query(gremlin=gremlin).first()
                save = False

                query.by_id(edge['_id'], model)
            except Exception, e:
                save = True
コード例 #4
0
    def test_can_make_get_edge_statement(self):
        out_id = 1
        in_id = 9
        label = 'knows'
        g = Gremlin()
        e = GetEdge(out_id, in_id, label)

        g.apply_statement(e)

        string = str(g)
        params = g.bound_params
        oid = get_dict_key(params, out_id)
        iid = get_dict_key(params, in_id)
        label_b = get_dict_key(params, label)
        as_b = get_dict_key(params, 'vertex')
        bound = (oid, label_b, as_b, iid, as_b)
        expected = 'g.v(%s).outE(%s).as(%s).inV.retain([g.v(%s)]).back(%s)' % bound

        self.assertEquals(expected, string)
        self.assertTrue(len(params) == 4)
コード例 #5
0
    def test_can_make_get_edge_statement_out_direction(self):
        out_id = 1
        in_id = 9
        label = 'knows'
        g = Gremlin()
        e = GetEdge(out_id, in_id, label, 'out')

        g.apply_statement(e)

        string = str(g)
        params = g.bound_params
        oid = get_dict_key(params, out_id)
        iid = get_dict_key(params, in_id)
        label_b = get_dict_key(params, label)
        as_b = e.bound_entity
        bound = (oid, label_b, as_b, iid, as_b)
        expected = 'g.V(%s).outE(%s).as(%s).inV().hasId(%s).select(%s)' % \
            bound

        self.assertEqual(expected, string)