Last active
April 20, 2017 10:50
-
-
Save retrography/69fea7a5084d1ef1538b to your computer and use it in GitHub Desktop.
Useful functions for OrientDB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createEdge (from, to, type) { | |
var g = orient.getGraph(); | |
var cmd = "CREATE EDGE " + type + " FROM " + from + " TO " + to; | |
return g.command("sql", cmd); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function dateDiff (from, to) { | |
// The number of milliseconds in one day | |
var ONE_DAY = 1000 * 60 * 60 * 24 | |
// Convert both dates to milliseconds | |
var to_ms = to.getTime() | |
var from_ms = from.getTime() | |
// Calculate the difference in milliseconds | |
var difference_ms = to_ms - from_ms | |
// Convert back to days and return | |
return Math.round(difference_ms / ONE_DAY) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getRID (className, property, condition, value) { | |
var g = orient.getGraph(); | |
var qry = "SELECT FROM " + className + " WHERE " + property + " " + condition + " '" + value + "'"; | |
res = g.command("sql", qry); | |
if (res.length == 0) { | |
return; | |
} | |
else { | |
rid = res[0].getId().toString(); | |
return rid; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment