以下是我每天的OrientDB问题:
在通过REST执行一批命令时,有可能忽略错误吗?
我使用以下命令在节点之间创建边缘
CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE account = '<theId>') TO (SELECT FROM Employee WHERE account = '<theId>')事实上,有时指定的帐户不在DB中,因此我得到以下错误:
Error:com.orientechnologies.orient.core.exception.OCommandExecutionException: No edge has been created because no source vertices由于我不能创建一些边缘,所以我想跳过返回的错误,以便尽可能多地插入边缘。
目前,我正在一个接一个地插入边缘,我认为使用批处理插入会大大加快这个过程。
发布于 2015-10-26 10:20:06
最后,我遵循了@Wolf4ood的建议:我创建了一个insert_edge JS服务器函数,为我想要创建的每个边缘调用该函数。如果目标节点和源节点存在,则创建边缘,否则不采取任何操作。这是它的身体:
var g = orient.getGraph();
var fromQ = "SELECT FROM " + fromTable + " WHERE " + fromField + " = '" + fromValue + "';";
var toQ = "SELECT FROM " + toTable + " WHERE " + toField + " = '" + toValue + "';";
var from = g.command('sql', fromQ, []);
var to = g.command('sql', toQ, []);
if(from.length > 0 && to.length > 0) {
var createQ = "CREATE EDGE " + edgeType + " FROM (SELECT FROM " + fromTable + " WHERE " + fromField + " = '" + fromValue + "')" + " TO (SELECT FROM " + toTable + " WHERE " + toField + " = '" + toValue + "');";
return g.command('sql', createQ, []);
}
return null;参数为fromTable, fromField, fromValue, sourceTable, sourceField, sourceValue, edgeType。我是这样调用这个函数的:
SELECT insert_edge('Employee', 'account', <theId>, 'Employee', 'account', <theManager>, 'ManagedBy')https://stackoverflow.com/questions/33259827
复制相似问题