create an edge from json

63 views
Skip to first unread message

loadedlux

unread,
Jul 22, 2015, 12:09:48 AM7/22/15
to OrientDB
Greetings,

Does anyone have any insight on creating an edge from JSON using the graphAPI. When working with a vertex, I can create an empty vertex, retreive the record, and call the fromJSON method.  However, there deosn't appear to be a means for creating an empty edge. Any help would be much appreciated.

Thanks.

Giulia Brignoli

unread,
Jul 22, 2015, 3:28:20 AM7/22/15
to OrientDB
Hi loadedlux,

I'm not very clear what you want:
you want to create an edge between two vertex using GraphAPI, right?

Bye
Giulia

loadedlux

unread,
Jul 22, 2015, 8:08:27 AM7/22/15
to OrientDB
Yes. But I would like to use JSON to create the edge.

loadedlux

unread,
Aug 4, 2015, 10:52:47 PM8/4/15
to OrientDB
Is it not possible to create an edge from JSON using the graph API?

normanLinux

unread,
Aug 6, 2015, 9:12:01 AM8/6/15
to OrientDB
I used a javascript function to abstract edge creation from JSON data sent from Angular.  

I was having trouble extracting relevant data from my JSON (needed because of the avstraction) and Alessandro posted this reply - which works perfectly

I hope that it helps you.  This forum is really great for anybody trying to get to grips with Orient!
=================
try this function with the parameter record {"from_rid": "#12:0","to_rid": "12:1", "edge_type": "friend","edge_properties":{"property1":"value_property", "property2":"value2_property"}}

var obj = JSON.parse(record);
var ridFrom=  obj.from_rid;
var ridTo = obj.to_rid;
var edge_type= obj.edge_type;
var edge_properties= obj.edge_properties;
var property1=edge_properties.property1;
var property2=edge_properties.property2;
var set=" set "+Object.keys(edge_properties)[0] + " = '" + property1 + "', " + 
    Object.keys(edge_properties)[1] + " = '" + property2 + "'"
var query="create edge "+ edge_type + " from " + ridFrom + " to " + ridTo + set ;
var g=orient.getGraph();
g.command('sql',query);

Alessandro
===========================================
Reply all
Reply to author
Forward
0 new messages