【发布时间】:2016-10-03 21:54:01
【问题描述】:
如何使用 orientjs 在事务中插入优势?我当前的实现插入两个顶点并总是创建一个新边:
function add(db, from, edge, to, cb) {
cb = cb || function() {};
log(
'[' + from.clazz + ']' + JSON.stringify(from.attributes) + ' ' +
'-[' + edge.clazz + ']' + JSON.stringify(edge.attributes) + '> ' +
'[' + to.clazz + ']' + JSON.stringify(to.attributes)
);
db.let('source', function(s) {
s.update(from.clazz)
.set(from.attributes)
.upsert()
.where(from.attributes)
.return('after @this');
})
.let('destination', function(d) {
d.update(to.clazz)
.set(to.attributes)
.upsert()
.where(to.attributes)
.return('after @this');
})
.let('edge', function(e) {
e.create('EDGE', edge.clazz)
.from('$source')
.to('$destination')
.set(edge.attributes);
})
.commit()
.return('$edge')
.all()
.then(cb);
}
【问题讨论】:
-
您使用的是哪个版本?从 2.2 开始,您可以使用
UPDATE EDGE参见:orientdb.com/docs/last/SQL-Update-Edge.html -
orientdb 在 2.1.19,orientjs 在 2.2.1。我也许可以升级两者。但在文档中,我看不到
UPDATE EDGE的UPSERT。UPDATE EDGE会自动插入边缘吗? -
你是对的,更新边缘没有 upsert。如果你的边缘已经存在,你可以使用更新。
标签: javascript orientdb orientjs