OrientDB REST API ignoreError
OrientDB REST API ignoreError
这是我每天的 OrientDB 问题:
是否可以在通过 REST 执行一批命令期间忽略错误 API?
我正在使用
等命令在节点之间创建边
CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE account = '<theId>') TO (SELECT FROM Employee WHERE account = '<theId>')
事实是有时指定的帐户不在数据库中,因此我得到以下错误:
Error:com.orientechnologies.orient.core.exception.OCommandExecutionException: No edge has been created because no source vertices
由于我对无法创建边这一事实感到满意,因此我想跳过返回的错误以便插入尽可能多的边。
目前我正在一条一条地插入边,我认为使用批量插入会大大加快这个过程。
最后我听从了@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')
这是我每天的 OrientDB 问题:
是否可以在通过 REST 执行一批命令期间忽略错误 API?
我正在使用
等命令在节点之间创建边CREATE EDGE ManagedBy FROM (SELECT FROM Employee WHERE account = '<theId>') TO (SELECT FROM Employee WHERE account = '<theId>')
事实是有时指定的帐户不在数据库中,因此我得到以下错误:
Error:com.orientechnologies.orient.core.exception.OCommandExecutionException: No edge has been created because no source vertices
由于我对无法创建边这一事实感到满意,因此我想跳过返回的错误以便插入尽可能多的边。
目前我正在一条一条地插入边,我认为使用批量插入会大大加快这个过程。
最后我听从了@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')