Creates a new Server-side javascript function. You can execute Functions from SQL, HTTP and Java.
Create Find Node Function :
Create Edge between to vertex node function :
Syntax :
CREATE FUNCTION <name> <code>
[PARAMETERS [<comma-separated list of parameters' name>]]
[IDEMPOTENT true|false]
[LANGUAGE <language>]
<name>
Defines the function name.<code>
Defines the function code.PARAMETERS
Defines a comma-separated list of parameters bound to the execution heap. You must wrap your parameters list in square brackets [].IDEMPOTENT
Defines whether the function can change the database status. This is useful given that HTTP GET can callIDEMPOTENT
functions, while others are called by HTTP POST. By default, it is set toFALSE
.LANGUAGE
Defines the language to use. By default, it is set to JavaScript.
Examples:
Create Vertex Node :/*
@ADD Function
* Function name : createVertex
* Language : javascript
* Idempotent : true
@Add new parameter:
* value
@Url Api
http://<domainname>:2480/function/<database_name>/<function_name>/<parameter>
*/
return createVertex (value);
function createVertex(value){
var db = orient.getDatabase();
var result = db.save({ "@class" : "Data", data_value : value });
db.commit();
return result;
}
/*
@ADD Function
* Function name: findNodeFunction
* Language : javascript
* Idempotent : true
@Add new parameter:
* name
@Url Api
http://<domainname>:2480/function/<database_name>/findNodeFunction/<parameter>
*/
return findNodeFunction (name);
function findNodeFunction (name){
return db.command("select from V where name='"+name+"'");
}
Create Edge between to vertex node function :
/*
@ADD Function
* Function name : createEdgeBtwVertex
* Language : javascript
* Idempotent : true
@Add new parameter:
* edge_name
* v1_name
* v2_name
@Url Api
http://<domainname>:2480/function/<database_name>/createEdgeBtwVertex/<parameter>
*/
return createEdgeBtwVertex (edge_name,v1_name,v2_name);
function createEdgeBtwVertex(edge_name,v1_name,v2_name){
var db = orient.getDatabase();
var edge_query="create edge "+edge_name+" from(select from v where name='"+v1_name+"') to (select from v where data_value='"+v2_name+"')";
var result_edge = db.command(edge_query);
return result_edge;
}
ReplyDeleteThanks for sharing this great article! That is very interesting I love reading and I am always searching for informative articles like this.
Struts Training in Chennai
Struts Training in Velachery
Struts Training in Tambaram
Wordpress Training in Chennai
Wordpress course in Chennai
Struts Training in Chennai
Struts course in Chennai