如何使用 orientjs 在事务中插入优势?我当前的实现 upserts 两个顶点并总是创建一个新的边缘:
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);
}