Skip to content

Instantly share code, notes, and snippets.

@retrography
Last active April 20, 2017 10:50
Show Gist options
  • Save retrography/69fea7a5084d1ef1538b to your computer and use it in GitHub Desktop.
Save retrography/69fea7a5084d1ef1538b to your computer and use it in GitHub Desktop.
Useful functions for OrientDB
function createEdge (from, to, type) {
var g = orient.getGraph();
var cmd = "CREATE EDGE " + type + " FROM " + from + " TO " + to;
return g.command("sql", cmd);
}
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)
}
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