Skip to content
Giraldo Rosales edited this page Jan 23, 2014 · 11 revisions

The GraphDB functionality extends the document functionality. You may use all the document methods. The only difference is calling orientdb.GraphDb instead of orientdb.Db. See the example in the open method below. The default type of database is also set to graph.

###Open

This is the first operation the client should call. It opens the default database specified in the node-orientdb configuration or you can specify another database to access. Returns the session ID to be reused for all the next calls and the list of configured clusters.

db.open(function(error){});
db.open(databaseName, databaseType, function(error){});
  • databaseName - (string) Name of the database. Optional.
  • databaseType - (string) Type of database. Either document or graph. Optional.
  • callback - (function) Callback
    • error - (string) Any errors that may be returned. Null if no errors.
    • result - (array) An array of databases on the server.
      • obj - (object) Database object.
        • sessionId - (string) Database name.
        • clusters - (array) Path to database.
          • id - (numeric) Id.
          • name - (string) Name of cluster.
          • type - (string) Cluster type.
          • dataSegmentId - (numeric) Data segment id.
        • config - (string) Is always null unless you're running in a server clustered configuration.
        • release - (string) Version of OrientDB release deployed on server and optionally build number. Example: "1.4.0-SNAPSHOT (build 13)"

Example

var orientdb = require("orientdb-binary"),
var Db       = orientdb.GraphDb;

var dbConfig = {
    username:"admin",
    password:"admin",
    database:"test",
    host: "localhost",
    port: 2424,
    database_type: "graph", //Optional. Default: graph.
    storage_type: "local" //Optional. Default: local.
};

var db = new Db(dbConfig);

db.open(function(error) {
    if(error) {
        console.log(error);
        return;
    }

    //Details
    console.log("Database '" + db.databaseName + "' has " + db.clusters.length + " clusters");

    //Queries
    db.getInEdges("#9:5", "isFollowing", function(error, results){
        db.close();
        
        if(error) {
            console.log(error);
            return;
        }

        console.log(results);
    });
});

##Vertex More on Vertices....

###Create a New Vertex Shortcut for: "CREATE VERTEX [@class] CLUSTER clusterName SET [field=value, ...]"

db.vertexCreate(vertex, function (error, results) {});
  • vertex - (object) Data to create a new vertex.
    • @class - (string) Class to create new record. Optional. Default: "V".
    • [custom] - (*) custom fields within record.
  • callback - (function) Callback
    • error - (string) Any errors that may be returned. Null if no errors.
    • result - (object) Vertex object
      • @rid - (string) Formatted record ID of the vertex.
      • @class - (string) Class of the vertex record.
      • @version - (numeric) The version of the new vertex.
      • @type - (string) Type of record.
      • [custom] - (*) custom fields within record.

###Delete a Vertex Shortcut for: "DELETE VERTEX [@rid | @class] WHERE [condition] LIMIT [limit]"

db.vertexDelete(vertex, condition, limit, function (error, results) {});
  • vertex - (string | object) May be a formatted record ID as a string (ie. "#9:5") or as a document object. Required.
  • condition - (string) The condition for the WHERE statement. Optional. Default: "".
  • limit - (numeric) A limit on how many items to delete. -1 removes the limit. Optional. Default: -1.
  • callback - (function) Callback
    • error - (string) Any errors that may be returned. Null if no errors.
    • result - (object) Vertex object
      • status - (boolean) 1 if deletion was successful. 0 if not.

Edges

Edges in the graph database. Edges, together with Vertices, are the main components of a Graph. OrientDB supports polymorphism on edges. More on Edges...

###Create Edge Shortcut for: "CREATE EDGE [@class] CLUSTER [clusterName] FROM [fromRID] TO [toRID] SET [field=value, ...]"

db.createEdge(fromRID, toRID, edge, function (error, results) {});
  • fromRID - (string | object) The Record ID from the source. May pass the record ID as a string ("#9:5") or as an object with the cluster ID and cluster position. Required. * recordId - (numeric) Formatted record ID. * clusterId - (numeric) The cluster the record belongs to. * clusterPosition - (numeric) Cluster position.depending on record type.
  • toRID - (string | object) The Record ID to the destination. May pass the record ID as a string ("#9:5") or as an object with the cluster ID and cluster position. Required. * recordId - (numeric) Formatted record ID. * clusterId - (numeric) The cluster the record belongs to. * clusterPosition - (numeric) Cluster position.depending on record type.
  • edge - (object) Data to create a new vertex.
    • @class - (string) Class to create new record. Required (unless clusterId is specified).
    • [custom] - (*) custom fields within record.
  • callback - (function) Callback
    • error - (string) Any errors that may be returned. Null if no errors.
    • result - (object) Edge object
      • @rid - (object) Edge ID.
        • recordId - (numeric) Formatted record ID.
        • clusterId - (numeric) The cluster the record belongs to.
        • clusterPosition - (numeric) Cluster position.depending on record type.
      • @class - (string) Class of the edge record.
      • @version - (numeric) The version of the new edge.
      • @type - (string) Type of record.
      • in - (object) This is the record ID of the destination record.
        • recordId - (numeric) Formatted record ID.
        • clusterId - (numeric) The cluster the record belongs to.
        • clusterPosition - (numeric) Cluster position.depending on record type.
      • out - (object) This is the record ID of the source record.
        • recordId - (numeric) Formatted record ID.
        • clusterId - (numeric) The cluster the record belongs to.
        • clusterPosition - (numeric) Cluster position.depending on record type.
      • [custom] - (*) custom fields within record.

Example

//Example of adding an edge
var edge = {
    '@class':'isFollowing',
    'date':'2014-01-10'
};

db.createEdge('#9:5', '#9:6', edge, function(error, result){
    console.log(result);
});

###Get Out Vertices Get the vertices going out of a vertex. (vertex)->(OUT). This is a shortcut for: SELECT expand(in) FROM (SELECT expand(out_[edgeClass]) FROM [vertex])

db.fromVertex(vertex).out(edgeClass, function (error, results) {});

###Get In Vertices Get the vertices going into a vertex. (IN)->(vertex). This is a shortcut for: SELECT expand(out) FROM (SELECT expand(in_[edgeClass]) FROM [vertex])

db.fromVertex(vertex).out(edgeClass, function (error, results) {});

Clone this wiki locally