Embedding record from function in OrientDB

回眸只為那壹抹淺笑 提交于 2019-12-11 17:27:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!