Search code examples
javascriptorientdb

How to fetch out and in values of edge class records in orientdb using javascript function


var g=orient.getGraph();

var sqlClassRecords = 'select * from ' + paramClass;

var listRecords = g.command('sql',sqlClassRecords);

return listRecords;

The above lines provide metadata plus out and in values for the edge.Like this:

[ { "@type": "d", "@rid": "#46:0", "@version": 1, "@class": "relatesTo", "out": "#28:1", "in": "#28:2", "@fieldTypes": "out=x,in=x" } ]

How can i fetch this out (#28:1) and in (#28:2) values using js function. listRecords[i].getRecord().field("out") is not working fine. It gives the vertex classes to along with the rids. I want only rids .


Solution

  • You just need to add another getRecord().field() to get its rids like:

    var g = orient.getGraph();
    
    var sqlClassRecords = 'select * from ' + paramClass;
    
    var listRecords = g.command('sql',sqlClassRecords);
    
    var result = [];
    
    for(var i = 0; i < listRecords.length; i++)
    {
        var out_ = listRecords[i].getRecord().field('out').getRecord().field('@rid').toString();
        var in_ = listRecords[i].getRecord().field('in').getRecord().field('@rid').toString();
        result.push(new Array("out: " + out_, "in: " + in_));
    }
    
    return result;