Reputation: 21
I'm working with Orient DB, I'm using Java APIs to insert data and query the data. Those are working fine. But I'm not getting good documentation on the REST APIs. I want to now call Orient DB's REST API to query the data on the fly from client side javascript and consume the JSON output and display it on the frontend application.
V1
/ \
E1 E2
/ \
V2 V3
/ \ / \
E3 E3 E4 E4
/ \ / \
V5 V6 V7 V8
This is my typical/simplest of graph in my application and following are the queries whose output i need to consume in javascript. I would like to traverse the graph from top to bottom and bottom to top with some filtering conditions on vertex properties. 1. Select from V1 2. Traverse out() from v1 3. Traverse in() from V5
In Java, I iterate over vertex.getEdges() and get to adjacent vertices like edge.getVertex(Direction.IN) at all levels of the graph.
But from the javascript i want to consume output of any query that I pass to it and get all properties of the vertex and the properties of vertices connected by all its edges.
Could someone show me how to do it, it would be great help for my project.
Upvotes: 2
Views: 303
Reputation: 1369
You can use this little function:
var g=orient.getGraph();
var b=g.command("sql", myQuery);
return b;
And save it in Studio -> Functions:
Than you can call it via HTTP REST using this String:
http://localhost:2480/command/GratefulDeadConcerts/sql/select expand(result) from(select sqlFunc("select from v") as result)
GratefulDeadConcerts
is DB name, select from v
is the query you want to pass.
I have tested it in the Postman and you will get the output in JSON as you can see:
Hope it helps.
Upvotes: 1