问题
I'd like to embed a record into another one using a function in OrientDB.
I have a class called Backup. Here's it's definition:
create class Backup extends V
create property Backup.dateTime datetime
create property Backup.record embedded V
What I want to do is to call an OrientDB function, passing it an arbitrary @rid, and it will make a backup of that record for me. Here's what I tried so far:
//function createBackup(id)
var gdb = orient.getGraphNoTx();
var rec = gdb.command("sql", "select from V where @rid = ?", [id]);
var v = gdb.command("sql", "create vertex Backup set dateTime = ?, record = ?", [(new Date().getTime()), rec[0].getRecord().toJSON()]);
...
Tried using rec[0], or rec[0].getRecord() instead, but function always throws an error at me. Any ideas?
回答1:
OrientDB - v2.0.6
var graph = orient.getGraphNoTx();
var query = "select @this.exclude('@rid').toJson() as json from V where @rid = " + id;
var result = graph.command("sql", query);
var command = "create vertex Backup "
+ "set dateTime = " + new Date().getTime() + ", "
+ " record = " + result[0].getRecord().field('json');
graph.command("sql", command);
return;
来源:https://stackoverflow.com/questions/29515487/embedding-record-from-function-in-orientdb